I can get the 'name' values but not the 'Orders' seems the Orders are returned as object not Array?
json.json
[{ "ID":"23",
"LastName":"Moe",
"FirstName":"Ronnie",
"Orders":[{"OrderNumber":"11","ItemNumber":"22"},
{"OrderNumber":"33","ItemNumber":"44"}]}]
myHTML.html
$.getJSON('json.json',
{},
function (data) {
$.each( data, function ( i, val ) {
var lastname=this.LastName;
var firstname=this.FirstName;
var orders=this.Orders;
$.each(data.Orders, function(property, value) {
alert(property + "=" + value);
//Insert the data to HTML page
$(".title").append('<li>'+lastname+', '+firstname+' >'+'</li>');
$(".title").append('<li>'+orders+'</li>');
});
});
})
});
2 Answers 2
Should be this.Orders or val.Orders, not data.Orders
Comments
See this fiddle http://jsfiddle.net/KyleMuir/jcr79/3 as mentioned below - you are iterating over data twice. You need to point to the correct datasource.
As for the alert, you need to alert the properties for the object, not the whole object. E.g. alert(value.OrderNumber)
Alert will simply print out the string representation of the object ("[object object]").
Console.log will log the entire object.
Hope this helps :)
3 Comments
Explore related questions
See similar questions with these tags.
alert(value.OrderNumber)or something similar you will see values.