I have some json from a remote server and the results are returned like this:
[{"item1":"tag1","a1":"b1"},{"item2":"tag2","a2":"b2"}]
How would I get the value of a1 and a2?
Thanks
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Use
JSON.parse()if the data is still in string form:Demo: http://jsfiddle.net/mattball/WK9gz/
Since you’re using jQuery, swap out
$.get()for$.getJSON()and jQuery will automagically parse the JSON for you. Inside of thesuccesscallback, you’ll have a normal JavaScript object to work with — no parsing required.