0

我想阅读下面的 json 数组。

[{"bus_code":"1103030017","bus_name":"Tony\u0027s Sports Bar \u0026 Grill","first_name":"","last_name":"","email":"tonyssports@bellsouth.net","phone":"(770) 552-2233","street_address":"8610 Roswell Rd","city":"Sandy Springs","state":"GA","zip_code":"30350","website":"www.tonyssportsbar.com/","open_hours":"Mon-Fri 11am-2am, Sat-Sun 12pm-2am","features":"Live entertainment, TVs, billiards, Wi-Fi. ","type":"Sports Bar, Restaurant","coords":"33.989659, -84.351690"}]

使用此代码但未成功

info = jQuery.parseJSON(data);

alert(info.bus_code);

但没有获得成功。

请建议我任何想法。

4

3 回答 3

4

尝试:

alert(info[0].bus_code);

(对象在一个数组中)。

于 2013-09-02T17:04:14.533 回答
2

您的数据已经是 JSON 格式。所以不需要使用jQuery.parseJSON(data)它是一个数组所以使用data[0].bus_code

 var data = [{"bus_code":"1103030017","bus_name":"Tony\u0027s Sports Bar \u0026 Grill","first_name":"","last_name":"","email":"tonyssports@bellsouth.net","phone":"(770) 552-2233","street_address":"8610 Roswell Rd","city":"Sandy Springs","state":"GA","zip_code":"30350","website":"www.tonyssportsbar.com/","open_hours":"Mon-Fri 11am-2am, Sat-Sun 12pm-2am","features":"Live entertainment, TVs, billiards, Wi-Fi. ","type":"Sports Bar, Restaurant","coords":"33.989659, -84.351690"}];
 console.log(data[0].bus_code);

小提琴

根据@Boaz,如果您输入的是字符串,那么您必须使用jQuery.parseJSON

于 2013-09-02T17:05:54.680 回答
2

试试这个。

alert(info[0]['bus_code']);

or

alert(info[0].bus_code);

看演示

于 2013-09-02T17:07:03.810 回答