$.getJSON(
"/html/aijquery/JSON.js"
,
function
(d){
$.each(d,
function
(i,v){
$(
"body"
).append(i+
"."
+v.name+
":"
+v.link+
"<br>"
);
});
});
<script>
//假設我們有下面這樣的一組json資料:
var
aijquery={
item1:{name:
"愛jquery"
,link:
"www.aijquery.cn"
},
item2:{name:
"學習jquery"
,link:
"aijquery.cn"
}
};
//可以直接用jquery裡的$.each來遍歷json:
$.each(aijquery,
function
(i,v){
document.write(i+
"."
+v.name+
":"
+v.link+
"<br>"
);
});