tags:

views:

1077

answers:

2

Here is my Json data:

[{"ok" : false,
  "details" : [{"n" : "Email",
                "v" : "The email address you entered is not correct."},
               {"n" : "NameFull",
                "v" : "Please enter your full name."}]
 }]

I found read sigle-level Json data is super-easy but for multi-level data like above I couldn't find an answer by search the internet. I just want to read above values. Like reading value from "n" and "v" under the "details".

+1  A: 

Sorry, maybe I don't understand your question. This doesn't work for you?

var data = eval('(' + strJson + ')');

Sorry for making misunderstood, I want to read some specific keys and values from that Json text above by using jQuery.
silent200: what you need the is jQuery.getJSON(), it will fetch a json from somewhere and do the eval for you. You don't need jquery to handle json, the support is "built into" javascript.
DrJokepu
Thank you DrJokepu! ;o)
silent200: My turn to apologize. I thought you know that eval() finction converts your JSON-encoded string into normal JavaScript object with properties and indexer. I certainly had to explain this clearly :)
+4  A: 

The data is inside an array

Note the square brackets around your data. You will have to index into the array in the above set of data.

This should let you access the email value:

var json = '[{"ok":false,"details":[{"n":"Email","v":"The email address you entered is not correct."},{"n":"NameFull","v":"Please enter your full name."}]}]';

var k = eval( json );

alert( k[0].details[0].v );

And this is the alert text that appeared:

The email address you entered is not correct.

Maybe your JSON source put it inside an array because they want to return multiple elements?

And actually, you don't need jQuery for this. JSON stands for JavaScript Object Notation. That basically means that it is a Javascript block of code that can be evaluated as-is directly in JavaScript to get the serialized data, which, in your case happens to be an array.

chakrit
Thank you! It works! I'm a super newbie, did you mean that I Json data I provided is not a standard Json?Thanks again!!!
It is a standard JSON, it's just inside an array.
chakrit