in my jquery code, I made an ajax request and the server returned the data in JSON as follows:
{"list":{ "category":"book", "item":[ {"title":"jQuery Cookbook","author":"Tom","publisher":"Wonderland"}, {"title":"PHP Cookbook","author":"Jack London","publisher":"O'Reilly"} ] } }
in my jquery code, I have:
$.getJSON( "data/getFile.php", {set:setName, list:listName}, function(json) { var items = json.list.item; $.each(items, function(key, value) {alert(value);} });
it turned out that value is an object that is correct. my question is how can I parse both the name and value as: for element 1: key = "title", value = "jQuery Cookbook"; key = "author", value = "Tom"; ...
the reason I need to do this is to update the element dynamically, maybe later the user will add more key / value attribute, for example: {"isbn": "11223344"}
Thanks.
Ohana source share