如何访问此JSON文件中的Marie-Antoinette.json对象?我想获得对象的标题元素,但我似乎无法得到它的输出。这是我的JavaScript代码,它输出的对象,但我似乎无法访问对象的元素。使用JavaScript解析JSONP文件
$.ajax(
{
type: 'GET',
url: 'http://localhost:5984/movies/efadd5913f5cfd254b2861efd4001cb7',
//contentType: "application/json; charset=utf-8",
dataType: "JSONP",
jsonpCallback: 'callback',
//async: false,
success: function(r)
{
alert("ok");
$.each(r, function(index, value){ // iterating over each object
console.log(index);
if(index == "_attachments")
{
console.log(value); //how do I output the title ("Marie-Antoinette.json") and the other stuff in the object?
}
});
}
});
这是文件。我想访问的元素位于对象的“_attachments”元素中。
{
"_id": "efadd5913f5cfd254b2861efd4001cb7",
"_rev": "6-417588bbff9aa74726b11440a86a8532",
"_attachments": {
"Marie-Antoinette.json": {
"content_type": "application/json",
"revpos": 2,
"digest": "md5-Io/Pxakfp/4R8ntjQKWMDg==",
"length": 761,
"stub": true
}
}
}
我认为抛弃我的是它是_attachment部分中的对象。
http://jsfiddle.net/adeneo/ke61kj8j/ – adeneo