获取JSON从URL给出错误[对象对象]没有找到

问题描述:

我请求从URL的JSON数据,但它给错误的获取JSON从URL给出错误[对象对象]没有找到

GET HTTP://本地主机:10560/[对象%20Object] 404(未找到)

var mydata; 
$.getJSON({ 
    url: 'http://free.worldweatheronline.com/feed/weather.ashx?q=City,Country&callback=?&format=json&num_of_days=2&key=1111111111111111', 
    dataType: 'json', 
    success: function (data) { 
     mydata = data; 
     console.log(mydata); 
    } 
}); 

如何获取json文件并解析它?

+2

在你的代码中,Url是http://free.worldweatheronline.com/feed/weather。 ashx虽然在错误它说http:// localhost:10560/[object%20Object] 你确定,你没有丢失任何东西... –

+2

看起来你已经发布了错误的ajax调用 – Johan

你jQuery.getJSON()的使用是不正确,文档:http://api.jquery.com/jQuery.getJSON/

二者必选其一:

var mydata; 
$.getJSON("http://free.worldweatheronline.com/feed/weather.ashx?q=City,Country&callback=?&format=json&num_of_days=2&key=1111111111111111",function(data){ 
    console.log(data) 
}) 

OR:

var mydata; 
$.ajax({ 
    url: 'http://free.worldweatheronline.com/feed/weather.ashx?q=City,Country&callback=?&format=json&num_of_days=2&key=1111111111111111', 
    dataType: 'jsonp', 
    success: function (data) { 
     mydata = data; 
     console.log(mydata); 
    } 
}); 

您可以点击此处查看做的一种方式这 - Consume Service Jquery Json