JSON获取数据

时间:2014-07-21 02:36:19

标签: jquery ajax json jqgrid

我正在尝试从以下JSON获取数据:

{
    "store": "4",
    "latestStatusChange.storeStatus": "OFFLINE",
    "latestStatusChange.transitionTime": "2014 Jul 20 21:40:09",
    "lcp": "S2",
    "number30MinuteOldLocks": "3",
    "numberCurrentLocalLocks": "4",
    "numberErrorDeltas": "5",
    "numberUnsyncedDeltas": "6",
    "rail": "S2-2",
    "heartbeatTime": "2014 Jul 20 20:17:05"
}

如何从'latestStatusChange.transitionTime'属性中获取数据?

3 个答案:

答案 0 :(得分:1)

您可以执行以下操作:

$.ajax({
    url: 'http://example.com',
    method : "POST",
    dataType: "json",
    success : function($response){
        console.log($response['latestStatusChange.transitionTime']);
    }
});

答案 1 :(得分:0)

尝试喜欢

var text = '{"name":"John Johnson","street":"Oslo West 16","phone":"555 1234567"}'

var obj = JSON.parse(text);
debugger;
alert(obj.name);

Demo

答案 2 :(得分:0)

我假设你正在尝试使用点符号jsonobject.latestStatusChange.transitionTime。这不会起作用,因为它会尝试访问latestStatusChange作为对象和transitionTime的键。使用括号来访问它jsonobject['latestStatusChange.transitionTime']。如果在对象中没有json,则必须执行var jsonobject = JSON.parse(jsonstring);