简体   繁体   English

使用jQuery读取JSON响应

[英]Read json response using jquery

I want to read below json array. 我想阅读下面的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"}]

Using this code but not getting success 使用此代码但未成功

info = jQuery.parseJSON(data);

alert(info.bus_code);

but not getting success. 但没有成功。

please suggest me any idea. 请给我建议任何想法。

Try: 尝试:

alert(info[0].bus_code);

(The object is within an array). (对象在数组内)。

Yours data is already in JSON format. 您的数据已经是JSON格式。 so no need to use jQuery.parseJSON(data) and Its an array so use data[0].bus_code 因此无需使用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);

Fiddle 小提琴

As per @Boaz If you input is string then you have to surely use jQuery.parseJSON 按照@Boaz如果您输入的是字符串,则必须使用jQuery.parseJSON

Try this. 尝试这个。

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

or

alert(info[0].bus_code);

See Demo 观看演示

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM