无法将json格式推入数组

时间:2019-04-20 01:25:23

标签: javascript python jquery json ajax

我使用python json.dumps将字典数组打印到python shell中,然后将输出复制到一个名为test.json的JSON文件中。然后使用javascript $ .getJSON()函数获取数据,然后尝试将该数据解析为数组,但是什么也没发生

test.json文件就是这样。

[["42.886641", "-78.879354", "FURNITURE"], ["42.886641", "-78.879354", "DRAWING"], ["42.886641", "-78.879354", "BOOK"], ["42.886641", "-78.879354", "DRAWING"], ["42.886641", "-78.879354", "PORTRAIT"], ["42.886641", "-78.879354", "MAP"], ["42.886641", "-78.879354", "MAP"], ["42.886641", "-78.879354", "MAP"], ["42.886641", "-78.879354", "DRAWING"], ["42.886641", "-78.879354", "PORTRAIT"], ["42.886641", "-78.879354", "DRAWING"], ["42.886641", "-78.879354", "MAP"], ["42.886641", "-78.879354", "MAP"], ["42.886641", "-78.879354", "DRAWING"], ["42.886641", "-78.879354", "BLUE PRINTS"], ["42.915606", "-78.882276", "LAMP"], ["42.886641", "-78.879354", "PORTRAIT"], ["42.902908", "-78.884856", "PLAQUE"], ["42.884454", "-78.890315", "ABSTRACT"], ["42.886641", "-78.879354", "DRAWING"], ["42.93097", "-78.855969", "CANNONS"], ["42.902176", "-78.89826", "FIGURATIVE"], ["42.918798", "-78.829261", "FIGURATIVE AND RELIEF"]]

然后我尝试使用我从jquery文档中获得的技术将数据读入数组:

 var items = [];
$.getJSON( "ajax/test.json", function( data ) {
    $.each( data, function( key, val ) {
        console.log(key)
        items.push( "key + val" );
    });
});
console.log(items);

当我说console.log(key)和console.log(items)显示一个空数组时,什么都不会压入项,什么也不会进入控制台。不知道发生了什么事

0 个答案:

没有答案