我有脚本 jquery 用于从文件中加载 json,如下所示:
$.getJSON( "text.json", function( data ) {
var items = [];
$.each( data, function( key, val ) {
items.push( "<li id='" + key + "'>" + val + "</li>" );
});
$( "<ul/>", {
"class": "my-new-list",
html: items.join( "" )
}).appendTo( "body" );
});
结果:
- 价值
- 价值
- 价值
- 价值
- [对象对象]
- [对象对象],[对象对象],[对象对象],[对象对象],[对象对象]
我如何加载[对象对象]
也许我想成为这样:
- 价值
- 价值
- 价值
- 价值
- 值{}
-value
-value
-value - 值[]
-value{}
-value
-value
-value
-value{}
-value
-value
-value
-value{}
-value
-value
-value
-value{}
-value
-value
-value
-value{}
-value
-价值
-价值
我的问题是什么脚本。谢谢
(文本.json)
{
"sender":"",
"status":
{
"status":"DELIVERED",
"date_time":"2013-09-30 15:00:00",
},
"history":
[
{
"status":"DELIVERED",
"date_time":"2013-09-30 15:00:00",
},
{
"status":"BAD ADDRESS-UNKNOWN COMPANY",
"date_time":"2013-09-26 07:45:26",
}
]
}
我将在下面尝试这个脚本但不显示:(
$.getJSON( "text.json", function( data ) { var items = []; $.each( data, function( key, val ) { $.each( val, function( key1, val2 ) { items.push( "<li id='" + key + "'>" + val + "</li>" ); }); items.push( "<lo id='" + key2 + "'>" + val2 + "</lo>" );
});
$( "", { "class": "my-new-list", html: items.join( "" ) }).appendTo( "body" ); });