使用jquery模板渲染json

时间:2014-02-10 17:41:49

标签: javascript jquery json templates

我有Json输出

{ "IDsInThisList":"28184,28181,28180,28178","RowsReturned":"4","List" :[{"ContentID":28184,"ArticleType":"News","Headline":"Mobile Bytes","Article":"<p>HTC CFO Chialin Chang expects the manufacturer&rsquo;s fortunes to change for the better going in to 2014.</p>"}]}

我需要获取“标题”并使用jquery模板显示它,我通常使用{{:Headline}}但是因为某些原因它不起作用,可能是因为它在里面“List”,如何渲染“标题” ?

1 个答案:

答案 0 :(得分:3)

使用JSON.parse()解析字符串,然后使用a.List[0].Headline

进行访问
var a=JSON.parse('{ "IDsInThisList":"28184,28181,28180,28178","RowsReturned":"4","List" :[{"ContentID":28184,"ArticleType":"News","Headline":"Mobile Bytes","Article":"<p>HTC CFO Chialin Chang expects the manufacturer&rsquo;s fortunes to change for the better going in to 2014.</p>"}]}');

console.log(a.List[0].Headline);

Fiddle Demo