我尝试从ajax调用接收json数据,我想在javascript变量中分配这些响应,虽然它返回正确的数据,但也在浏览器中显示JSON.parse错误。
我有json编码响应,如:
{
"abcd.org": {
"auction_id": "113885",
"expiry_date_formatted": "2d 20h 52m",
"expiry_date": "2014-10-13 15:48:17.498803",
"buy_now_price": "6000",
"current_bid_price": "500"
}
}
使用:
获取$.ajax({
url: "domain-check-ajax.html?dont_render_template=1&result=" + domain,
timeout: 50000,
cache: false,
success: function(msg) {}
});
我正在解析它如下:
JSON.parse(msg, function (k, v){
switch(k){
case "auction_id":
auction_id = v;
break;
case "buy_now_price":
buy_now_price = v;
break;
case "current_bid_price":
current_bid_price = v;
break;
}
});
但它显示了我
**SyntaxError: JSON.parse: unexpected end of data
[Break On This Error] JSON.parse(msg, function (k, v){**
答案 0 :(得分:-2)
试试这个
getJSON('URL', function(data) {
alert('Your public IP address is: ' + data.ip);
}