Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Parse JSON in JavaScript?

    • 0
    • 1
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 146
    Comment on it

    Suppose you have response somewhat like this:

    var response = '{"result":true,"total-count":1}';
    var getValues = JSON.parse(response);
    document.write(getValues.result + ", " + getValues.total-count;

    You can simple use JSON.parse() method to get the values of your response and then use it accordingly. Most of the browsers support JSON.parse().

    Also you need to make to sure that your JSON code is valid.

    You can also use eval function for this purpose. But it is not recommended if you are getting the JSON object from another source that isn't absolutely trusted.

    Here is an example of using eval:-

    var response = '{"result":true,"total-count":1}';
    var getValues =  eval("(function(){return " + response + ";})()");
    alert(getValues.result);
    alert(getValues.total-count);
    

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: