【发布时间】:2013-12-12 05:43:19
【问题描述】:
我正在尝试查看一个对象,但基于结构我不知道如何获取数据。
对象:
{
"177":{
"text":"test text",
"user_name":"Admin",
"date":"1385494358",
"docs":{
"document_name": [
"marketing_service",
"maintenance_service",
"development_service"],
"document_type":[
"png",
"png",
"png"]
}
},
"174":{
"text":"Some more images",
"user_name":"Admin",
"date":"1385493618",
"docs":{
"document_name": [
"marketing_service16",
"maintenance_service53"],
"document_type":[
"png","png"]
}
}
}
我在 jQuery 中尝试的循环
var obj = $.parseJSON(data);
$(obj).each(function(index, note) {
console.log(note.text + note.user_name + note.date_created);
});
它返回未定义。我做错了什么?
【问题讨论】:
-
什么是
data是字符串吗? -
data是上面代码中显示的对象
-
请准确说明您如何声明和设置
data。如果data已经是您不想使用$.parseJSON()的对象。
标签: javascript jquery json loops foreach