如何访问服务器返回的Json类型

How to access Json type returned from server?

本文关键字:返回 Json 类型 服务器 何访问 访问      更新时间:2024-04-05

伙计们,我收到了来自服务器的回复:

{"copy_am_email":"0","locations": [array here ... .....]}

我很确定这是一个json类型(我控制台记录了它)。上面的数据是通过ajax获取的:

success    : function ( data ) {
   alert (data.locations[index]); //I should be able to access locations even without index
}

但我的问题是locations是未定义的。甚至是CCD_ 2。我是这样访问的:

data.locations . I even tried this data['locations'].

u必须解析它:

newJSON = JSON.parse( myJson );

我应该注意,你有一个数字零作为字符串"0",它应该只是0

尝试使用javascript的本地方法JSON.parse(data)解析JSON数据。然后尝试以您的方式访问位置。