if you had:
var json = {"4":{"6":"1"},"3":{"1":"1","2":"1"}}
and this div:
<div id="Results"></div>
then this code:
$.each(json, function(Parent, Values) {
$("#Results").append("Parent: " + Parent + "</br />");
$.each(values, function(key, val) {
$("#Results").append("-- Key: " + key + ", Value: " +
val + "</br />");
});
});
Would result in
Parent: 4
-- Key: 6, Value 1
Parent 3
-- Key: 1, Value 1
-- Key: 2, Value 1
On May 4, 1:56 pm, Dman <[email protected]> wrote:
> Hello, I recently learnt jQuery but I am having problems on working
> with JSON. I am loading the JSON data from PHP file using $.getJSON.
> The JSON returned is {"4":{"6":"1"},"3":{"1":"1","2":"1"}} and array
> for reference is
> Array
> (
> [4] => Array
> (
> [6] => 1
> )
>
> [3] => Array
> (
> [1] => 1
> [2] => 1
> )
>
> )
> The problem is that I don't know the JSON values. Is there any way I
> can loop through JSON so I can access "4", its child "6" and value 1?
> Or I will have to make another JSON structure?