我有一個JSON對象,看起來像這樣:印刷JSON對象的jQuery到HTML
var content = '[{"title":"John Apple","lastname":"Apple"},
{"title":"Kumar Patel","lastname":"Patel"},
{"title":"Michaela Quinn","lastname":"Quinn"},
{"title":"Peyton Manning","lastname":"Manning"},
{"title":"John Doe","lastname":"Doe"},
{"title":"Jane Lee","lastname":"Lee"},
{"title":"Dan McMan","lastname":"McMan"},
{"title":"Yu Win","lastname":"Win"}]';
,我試圖用jQuery來編輯它在我div
標籤與content-view
這裏是我的jQuery:
$.each(content, function(t, l){
$('#view-content').appendTo('<div id = "' + l + '">' + t + '</div>');
});
有關我的jsfiddle,由於某種原因,這是在這裏:http://jsfiddle.net/gAWTV/
它只是結果空白。有沒有人有任何想法?我難倒...
---編輯---
我想要做的就是擁有的一切輸出到自己的div標籤是這樣的:
<div id="Apple">John Apple</div>
<div id="Patel">Kumar Patel</div>
<div id="Quinn">Michaela Quinn</div>
etc...
控制檯顯示: 不能使用「在」運營商[{「稱號」:「約翰蘋果」,「姓氏」:「蘋果」}搜索「332」,{「稱號」:「庫馬爾Patel「,」lastname「:」Patel「},{」title「:」Michaela Quinn「,」lastname「:」Quinn「},{」title「:」Peyton Manning「,」lastname「:」Manning「 {「title」:「John Doe」,「lastname」:「Doe」},{「title」:「Jane Lee」,「lastname」:「Lee」},{「title」:「Dan McMan」,「lastname 「:」McMan「},{」title「:」Yu Win「,」lastname「:」Win「}] – digitalextremist
哪裏有'in'運算符? – scapegoat17
不應該先將字符串解析爲對象嗎?看到這個:http://stackoverflow.com/questions/4935632/how-to-parse-json-in-javascript – SOReader