I have JSONArray Containing JSONObjects
[ { 'title': abc, 'details':xyz,}, {'title': abc2,'details':xyz2}]
How to parse it using jquery?
asked Mar 16, 2011 at 10:47
MalTec
1,3702 gold badges14 silver badges33 bronze badges
-
In what manner do you want to parse it? What is your desired output?David Hedlund– David Hedlund2011年03月16日 10:48:56 +00:00Commented Mar 16, 2011 at 10:48
-
1I'm not sure what your asking, do you have the JSON as a string or is it already and array of objects?Richard Adnams– Richard Adnams2011年03月16日 10:49:44 +00:00Commented Mar 16, 2011 at 10:49
2 Answers 2
parseJSON will convert your Json string into a javascript object. The code is something like
var array = $.parseJSON(json);
Then to access the variables you use code like
var title1 = array[0].title; //title1 is abc
answered Mar 16, 2011 at 10:55
Belinda
1,2272 gold badges14 silver badges25 bronze badges
Sign up to request clarification or add additional context in comments.
10 Comments
MalTec
is this function available with jquery1.4.3-min ?? i m not getting parseJSON in ide
Belinda
Version added 1.4.1 so it should be available.
MalTec
My json data contains HTML text.. & a URL too.. does it throw exception when using parseJSON?
Belinda
Once your string is encoded properly i.e. in double quotes it shouldn't throw an execption
MalTec
ohk.. i guess the issue is with HTML it contains string like: <img src=""> is there a solution for avoiding exceptions.. it finads end at double quotation of HTML data in JSON
|
I think you need to use parseJSON if your array is a string.
answered Mar 16, 2011 at 10:51
Thinker
14.5k9 gold badges42 silver badges56 bronze badges
Comments
lang-js