我正在接受服务回复,例如
{
"Name": [
[{
"Key": "A",
"Value": "Sample1"
}
],
[{
"Key": "A",
"Value": "Sample2"
}
],
[{
"Key": "A",
"Value": "Sample3"
}
],
[{
"Key": "A",
"Value": "Sample4"
}
]
],
"Title": "Office"
}
我需要输出为值字段。
我尝试了很多方法。但没有得到任何解决方案。请帮帮我..
答案 0 :(得分:1)
试试这个:
var obj = {"Name":[[{"Key":"A","Value":"Sample1"}],[{"Key":"A","Value":"Sample2"}],[{"Key":"A","Value":"Sample3"}],[{"Key":"A","Value":"Sample4"}]],"Title":"Office"}
$.each( obj.Name, function( key, d ) {
console.log( key + ": " + d[0].Value );
});
答案 1 :(得分:1)
var data= {"Name":[[{"Key":"A","Value":"Sample1"}],[{"Key":"A","Value":"Sample2"}],[{"Key":"A","Value":"Sample3"}],[{"Key":"A","Value":"Sample4"}]],"Title":"Office"};
var output = [];
for(var i = 0;i<data.Name.length;i++) // data is your JSON response
output.push(data.Name[i][0].Value);
alert(output);
Fiddle参考
答案 2 :(得分:1)
请看看这个jsfiddle http://jsfiddle.net/2dJAN/16/
var fields= {
"Name": [
[{
"Key": "A",
"Value": "Sample1"
}
],
[{
"Key": "A",
"Value": "Sample2"
}
],
[{
"Key": "A",
"Value": "Sample3"
}
],
[{
"Key": "A",
"Value": "Sample4"
}
]
],
"Title": "Office"
}
$.each(fields['Name'], function(index, value) {
$.each(value, function(index, innervalue) {
alert(innervalue['Value'])
});
});