Javascript 为什么这个JSON是未定义的?

Javascript 为什么这个JSON是未定义的?,javascript,jquery,json,Javascript,Jquery,Json,当我调用JSON.bridge\u time时,为什么这个JSON没有定义 {"tunnel_time": 0,"bridge_time": 0} 如果有区别,下面是我调用它的代码: $.get( "http://localhost:8000/us", function(json){ console.log(json); $('#timeone').html(json.bridge_time + "min delay"); $('#timetwo').html(json.tun

当我调用
JSON.bridge\u time
时,为什么这个JSON没有定义

{"tunnel_time": 0,"bridge_time": 0}
如果有区别,下面是我调用它的代码:

$.get( "http://localhost:8000/us", function(json){
console.log(json);
    $('#timeone').html(json.bridge_time + "min delay");
    $('#timetwo').html(json.tunnel_time + "min delay");
})
.fail(function(){
    alert('We can\'t get data right now! Please try again later.');
})
.done(function(){
    alert('Success!');
});

很可能是由于发送了头,jqueryajax没有将数据识别为
json
。您可以设置
$的
数据类型
。获取
,以便jQuery知道需要
json
,或者使用
$。getJSON
已经设置了
数据类型

使用
$。获取

$.get('url',function(response){
   /*response  should be object now*/
},'json');/* last argument is "dataType" */


还应考虑在服务器上为
应用程序/json

设置适当的
内容类型
头,尝试添加
'json'
作为
$的第三个参数。获取
设置数据类型,或尝试
$。getJSON
@Shomz你是什么意思?这是
控制台。记录
json
的输出?它是对象还是字符串?什么
Content-Type
header是发送的终点?console.log(json)
show是什么?@kennypu正如我在问题中所说的那样