简体   繁体   中英

JSON array data return Undefined

am having the data sa

var data = '[{"idcoupons_tbl":"1","discount_percent":"10"}]';

when i try to parse and get a discount_percent ie

var result= jQuery.parseJSON(data); 
alert(result["discount_percent"]); 

FIDDLE it returns Undifined, thanks in advance

your variable result is an array, currently with 1 item, doing

result[0]["discount_percent"]

should work

As result is an array you need to use index.

result[0]["discount_percent"]

DEMO

var data = '[{"idcoupons_tbl":"1","discount_percent":"10"}]';  
var result = jQuery.parseJSON(data); 

alert(result[0].discount_percent); 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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