这是我的 test.json 文件:
[{"id":"12","url":"http:\/\/localhost\/test\/1\/images\/pic\/3.jpg"},
{"id":"11","url":"http:\/\/localhost\/test\/1\/images\/pic\/1.png"},
{"id":"10","url":"http:\/\/localhost\/test\/1\/images\/pic\/2.png"}]
我想使用jQuery在强调文本上打印它。
<div>12<img src="http://localhost/test/1/images/pic/3jpg" /></div>
<div>11<img src="http://localhost/test/1/images/pic/1jpg" /></div>
<div>10<img src="http://localhost/test/1/images/pic/2jpg" /></div>
答案 0 :(得分:1)
检查下面的有效JSON并尝试重新格式化你的,你也可以找到示例,告诉你如何使用for in
解析JSON对象来实现所需的结果。
希望这有帮助。
var test_json =
[
{"id":"12","url":"http:\/\/localhost\/test\/1\/images\/pic\/3.jpg"},
{"id":"11","url":"http:\/\/localhost\/test\/1\/images\/pic\/1.png"},
{"id":"10","url":"http:\/\/localhost\/test\/1\/images\/pic\/2.png"}
];
for ( var key in test_json )
{
console.log('<div>'+test_json[key].id+'<img src="'+test_json[key].url+'" /></div>');
}
答案 1 :(得分:1)