Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用Javascript管理我的json内容_Javascript_Json - Fatal编程技术网

如何使用Javascript管理我的json内容

如何使用Javascript管理我的json内容,javascript,json,Javascript,Json,我想恢复json的内容,但我不能。控制台“say uncaughttypeerror:cannotreadproperty'longitude'of undefined”我对这个方法非常陌生。如果你能帮助我,谢谢你 var recuptable = []; $(document).ready(function(){ $.ajax({ url: 'http://******', type: 'get', dataType:

我想恢复json的内容,但我不能。控制台“say uncaughttypeerror:cannotreadproperty'longitude'of undefined”我对这个方法非常陌生。如果你能帮助我,谢谢你

var recuptable = [];

     $(document).ready(function(){
     $.ajax({
         url: 'http://******',
         type: 'get',
         dataType: 'JSON',
         success: function(response){         

           recuptable.push(response);
         }

     });

 });

 console.log(recuptable[1].longitude);


代码是异步的,当控制台记录变量时,它仍然是空的。而是将console.log移到success函数中

var recuptable = [];

     $(document).ready(function(){
     $.ajax({
         url: 'http://******',
         type: 'get',
         dataType: 'JSON',
         success: function(response){         
           console.log(response.longitude);
           recuptable.push(response);
         }

     });

 });

另外,我建议您阅读一点有关回调和/或承诺的内容,以便能够更轻松地使用异步代码。

请查看,这两个内容重复了哪一个。@DaveNewton为什么不将其标记为这样?:)好的,谢谢你,戴夫,我检查了@TylerRoper,因为这台机器上的快捷方式由于一个未知的原因失败了,在我意识到之前我已经离线了。好的,谢谢你,我明白了。