The value of your message_array property is a quoted string, not an object. Note what $.each is giving you: every character of the string.
How are you generating the JSON data? That's where you need to fix this. With the extra newlines removed, your JSON data looks like this: { "processed": false, "message": "External link could not be set:", "message_array": "{\"link\":{\"isEmpty\":\"Value is required and can't be empty\"}}" } It should look like this: { "processed": false, "message": "External link could not be set:", "message_array": { "link": { "isEmpty": "Value is required and can't be empty" } } } The newlines and indentation are not significant (except inside a string). -Mike On Tue, Sep 29, 2009 at 3:28 AM, defdev <sp...@definitivedevelopment.co.uk>wrote: > > Hi, > > im sure this is a simple matter, but i cant seem to work out how to > loop through a multi dimensional JSON object (where the keys are > unknown). > > example json: > > { > "processed":false, > "message":"External link could not be set:", > "message_array": > "{ > \"link\": > { > \"isEmpty\":\"Value is required and > can't be empty\" > } > }" > } > > basically, i need to loop through the 'message_array' key and put each > error into an LI item. > > doing this: > > $.each(r, function( intIndex, objValue ) { > if (intIndex == 'message_array') { > html += "<li>" + intIndex + > ": " + objValue+ "</li>"; > } > }); > > puts the message_array bit into objValue, but thats where im stuck. > doing another each on that bit: > > $.each(objValue , function( field, errors) { > html += "<li>" + field+ ": " + errors+ > "</li>"; > }); > > results in a load of LI items like so: > > 0: { > 1: " > 2: l > 3: i > 4: n > 5: k > 6: " > 7: : > 8: { > 9: " > 10: i > 11: s > 12: E: > > ..... > etc > > > any help appreciated. > > >