Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3

Thread: json.parse help

  1. #1
    New to the CF scene
    Join Date
    Aug 2014
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    json.parse help

    hi all,

    I need a little help I am stuck on a problem I have never used json.parse before and I need to parse a string into 3 objects.

    here is my json string stored using stringify

    \"I\",\"2\",\"SR227\"

    Thanks in advance,
    Yonu

  2. #2
    Master Coder sunfighter's Avatar
    Join Date
    Jan 2011
    Location
    Washington
    Posts
    6,424
    Thanks
    30
    Thanked 878 Times in 876 Posts
    Could you give us what you started with, before stratification.
    Evolution - The non-random survival of random variants.
    Physics is actually atoms trying to understand themselves.

  3. #3
    New Coder
    Join Date
    Aug 2014
    Posts
    27
    Thanks
    0
    Thanked 1 Time in 1 Post
    A JSON parser will recognize only JSON text, rejecting all scripts.

    function locate(obj, path) {

    path = path.split('.');
    var arrayPattern = /(.+)\[(\d+)\]/;
    for (var i = 0; i < path.length; i++) {
    var match = arrayPattern.exec(path[i]);
    if (match) {
    obj = obj[match[1]][parseInt(match[2])];
    } else {
    obj = obj[path[i]];
    }
    }

    return obj;
    }

    var name = locate(test, 'items[0].name');


    try this, learn more about json.parse from tutorials which are available on web


 

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •