Gho*_*ozt 0 javascript jquery json
我在一个名为json/img_desc.json的文件夹中有一个json文件
这是json文件
{ "theimages":[
{
"number":1,
"title":"Joy Toy teddy bear",
"description":"In etc etc"
} etc etc
Run Code Online (Sandbox Code Playgroud)
然后我使用此代码尝试获取第一个值.
$.getJSON('json/img_desc.json', function(theimages) {
console.log(img_desc.theimages.number[0]);
});
Run Code Online (Sandbox Code Playgroud)
错误
它说这个
[15:06:46.951] ReferenceError:未定义img_desc @ file:/// [为隐私而删除] /js/puzzle.js:246
它应该是
$.getJSON('json/img_desc.json', function (theimages) {
console.log(theimages.theimages[0].number);
//if you want to loop
$.each(theimages.theimages, function (idx, obj) {
console.log(obj.number)
})
});
Run Code Online (Sandbox Code Playgroud)