doctor069
asked on
Jquery parseJSON - json
Hi - I am trying to parse a json object
I have 3 sets of data they are as follows
"from": {"name": "Bill Smith", "category": "Technology","id": "19292868552"}
"to": {"name": "Joe Hunt", "category": "Technology","id": "11204705797"}
"comments": {"name": "Sisi", "message": "Hi from Sisi", "id": "11204705797"},{"name": "Sara", "message": "Hi from Sarah", "id": "11204705797"}
I would like to create a json string/object and then have jquery parse the information
I can do it with 2 sets of data see code below...
Now i need to add the third set and parse/loop though though it!
Thanks in advance
I have 3 sets of data they are as follows
"from": {"name": "Bill Smith", "category": "Technology","id": "19292868552"}
"to": {"name": "Joe Hunt", "category": "Technology","id": "11204705797"}
"comments": {"name": "Sisi", "message": "Hi from Sisi", "id": "11204705797"},{"name": "Sara", "message": "Hi from Sarah", "id": "11204705797"}
I would like to create a json string/object and then have jquery parse the information
I can do it with 2 sets of data see code below...
Now i need to add the third set and parse/loop though though it!
Thanks in advance
------2 sets of data working!!!!-----------------------------------------------------
var obj = jQuery.parseJSON('{"from": {"name": "Bill Smith", "category": "Technology","id": "19292868552"}, "to": {"name": "Joe Hunt", "category": "Technology","id": "11204705797"}}');
alert(obj.from.name);
alert(obj.to.name);
-------------------------------------------------------------------------------------
'3 set of data I NEED HELP!!--------------------------------------------------------------
var obj = jQuery.parseJSON('{"from": {"name": "Bill Smith", "category": "Technology","id": "19292868552"}, "to": {"name": "Joe Hunt", "category": "Technology","id": "11204705797"}, "comments": [{"name": "Sisi", "message": "Hi from Sisi", "id": "11204705797"},{"name": "Sara", "message": "Hi from Sarah", "id": "11204705797"}] }');
alert(obj.from.name);
alert(obj.to.name);
***THIS IS WHERE I GET LOST!! I need it to loop in comments and give an output (for each)
alert(obj.comments.message); - NOT WORKING
The output I hope for would be...
Message1 "Bill Smith"
Message2 "Joe Hunt"
Message3 "Hi from Sisi"
Message4 "Hi from Sarah"
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
You're welcome! Thanks for the points!
ASKER