views:

104

answers:

3
var response = "{\"tree\":[{\"level1\":[{\"node\":{\"id\": 1,\"name\": \"paradox\",\"parent\": 0}}]},{\"level2\":[{\"node\":{\"id\": 2,\"name\": \"lucent\",\"parent\": 1}},{\"node\":{\"id\": 3,\"name\": \"reiso\",\"parent\": 1}}]},{\"level3\":[{\"node\":{\"id\": 4,\"name\": \"pessi\",\"parent\": 3}},{\"node\":{\"id\": 5,\"name\": \"misho\",\"parent\": 2}}]},{\"level4\":[{\"node\":{\"id\": 6,\"name\": \"hema\",\"parent\": 5}},{\"node\":{\"id\": 7,\"name\": \"iiyo\",\"parent\": 4}}]}]}";
var data = eval("(" + response + ")");

This is a dummy json response I am currently testing. Now how do I get the value of "name" in the 1st node of "level1" from the "tree"? Thanks

A: 
var level1name = data.tree[0].level1[0].node["name"];
ironsam
A: 

Firebug can be your friend, you could add a watch on the data var ( as i did ) to find this solution.

http://getfirebug.com/

alert(data.tree[0].level1[0].node.name);
John Boker
A: 
alert(data.tree[0].level1[0].node.name);
Abu Aqil