Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
141
rated 0 times [  148] [ 7]  / answers: 1 / hits: 34923  / 14 Years ago, mon, february 21, 2011, 12:00:00

I have the following Json string



{ Users : [ 
{ Name : user99,
Value : test
},
{ Name : test2,
Value : test
}
]
}


I am trying to parse it and print out each name and value - what is the easiest way to do this ?
I tried jQuery.parseJSON but I do not know how to use it I guess



Sample code would be great


More From » jquery

 Answers
0
var json = '{Users:[{Name:user999,Value:test},{Name:test2,Value:test}]}';

var json_parsed = $.parseJSON(json);

for (var u = 0; u < json_parsed.Users.length; u++){
var user = json_parsed.Users[u];
$('body').append($('<p>').html('User: '+user.Name+'<br />Value: '+user.Value));
}


Results in:



<p>User: user999<br />Value: test</p>
<p>User: test2<br />Value: test</p>


jsFiddle Example: http://jsfiddle.net/bradchristie/XtzjZ/1/


[#93642] Saturday, February 19, 2011, 14 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
andrewb

Total Points: 259
Total Questions: 124
Total Answers: 90

Location: Ivory Coast
Member since Sun, Mar 7, 2021
3 Years ago
;