我试图从生成以下对象的页面中获取数据,该对象在body和pre标签中显示为文本,但似乎没有获得所有4个键值对(仅3个)?
请注意我已经更改了jSON输出的网址,并删除了大部分数据以在此处缩短它。希望我没有引入任何错误。
{"nodes":[{"node":{"title":"NLT bottle 14","bottle_code":"NL_T14","bottle_img":"http:\/\/site.dev\/files\/bottles\/bottleimages\/nlt%20bottle%2014_bottle.jpg","swatch":"http:\/\/site.dev\/files\/bottles\/swatches\/nlt-bottle-14_swatch.jpg"}},{"node":{"title":"DS Bottle 033","bottle_code":"DS_033","bottle_img":"http:\/\/site.dev\/files\/bottles\/bottleimages\/ds%20bottle%20033_bottle.jpg","swatch":"http:\/\/site.dev\/files\/bottles\/swatches\/ds-bottle-033_swatch.jpg"}}]}
我试图通过以下方式获取:
var url = "http://site.dev/getinfo";
$.ajax({
url: url,
type: "GET",
dataType: "json",
async: true, // false loads and processes the data (function) before rendering the page
success: function(stuff){
console.log(stuff); // <- This output of the stuff object->nodes does not show the swatch key value pair!
process_data(stuff);
},
complete: function(){
doneprocess();
},
error: function(code){
error_get_data(code);
}
});
但我得到了没有 swatch键值对。我不知道为什么!
{"nodes":[{"node":{"title":"NLT bottle 14","bottle_code":"NL_T14","bottle_img":"http://site.dev/files/bottles/bottleimages/nlt%20bottle%2014_bottle.jpg"}},{"node":{"title":"DS Bottle 033","bottle_code":"DS_033","bottle_img":"http://site.dev/files/bottles/bottleimages/ds%20bottle%20033_bottle.jpg"}}]}
非常感谢您的专业知识!
答案 0 :(得分:0)
由于你传达了我们无法分辨的数据,所以一个显而易见的问题是:你确定JSON数据结构是否有效?
使用Web Inspector或Firebug检查浏览器是否获得了您认为服务器正在发送的数据。