2

URLからJSONデータをリクエストしていますが、次のようなエラーが発生します

GET http://localhost:10560/[object%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 ファイルを取得して解析するにはどうすればよいですか?

4

2 に答える 2

4

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)
})

また:

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);
   }
});
于 2013-01-23T09:35:56.340 に答える
2

これを行う1つの方法でここで確認できます-Consume Service Jquery Json

于 2013-01-23T10:21:10.803 に答える