3

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

2
  • 2
    result[0]["discount_percent"], it's an array Commented Apr 9, 2015 at 7:53
  • w3schools.com/js/js_json.asp alexeys answer works result[0].discount_percent Commented Apr 9, 2015 at 7:56

3 Answers 3

3

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

result[0]["discount_percent"]

should work

Sign up to request clarification or add additional context in comments.

Comments

3

As result is an array you need to use index.

result[0]["discount_percent"]

DEMO

Comments

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

alert(result[0].discount_percent); 

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.