I tried this on my side and I'm getting undefined for EditableRegions.erpagecontent, not EditableRegions. It might have something to do with the [[ ]]. That suggests a 2D array, but I'm not sure what you are going for with that data. Is "EditableRegions"
supposed to be an array of strings? If so, only use a single bracket and iterate through the array to access them.
"Dream as if you'll live forever, live as if you'll die today." --James Dean
airic82
Member
78 Points
223 Posts
Parsing JSON Problem
Dec 21, 2012 05:17 PM|LINK
Hi!
I'm going to just admit that this is my first experience trying to parse JSON within jQuery, so with that in mind....
Here's an example of my JSON string that my WebMethod is returning:
{"PageTitle":"Christ Community Chapel :: Our DNA","EditableRegions":[["erpagecontent","Test"]]}Or more properly formatted:
{ "PageTitle": "Christ Community Chapel :: Our DNA", "EditableRegions": [ [ "erpagecontent", "Test" ] ] }I verified its validity using JSONLint.com, but I'm having trouble accessing the erpagecontent value.
I thought it would be as simple as:
var jsonData = $.parseJSON(myjsonstr); $("#myDiv").append(jsonData.EditableRegions.erpagecontent);But I keep getting a JavaScript error that EditableRegions is null.
Could someone please give me some guidance?
Thanks!
-Eric
AceCorban
Star
12318 Points
2269 Posts
Re: Parsing JSON Problem
Dec 21, 2012 05:44 PM|LINK
I tried this on my side and I'm getting undefined for EditableRegions.erpagecontent, not EditableRegions. It might have something to do with the [[ ]]. That suggests a 2D array, but I'm not sure what you are going for with that data. Is "EditableRegions" supposed to be an array of strings? If so, only use a single bracket and iterate through the array to access them.
bruce (sqlwo...
All-Star
36644 Points
5432 Posts
Re: Parsing JSON Problem
Dec 21, 2012 09:35 PM|LINK
jsonData.EditableRegions is an array or arrays, so you want something like:
jsonData.EditableRegions[0][0] //erpagecontent
<div></div>jsonData.EditableRegions[0][1] //Test
asteranup
All-Star
30184 Points
4906 Posts
Re: Parsing JSON Problem
Dec 22, 2012 06:39 AM|LINK
Hi,
You can access the json like below-
Anup Das Gupta
Mark as Answer if you feel so. Visit My Blog
airic82
Member
78 Points
223 Posts
Re: Parsing JSON Problem
Dec 22, 2012 05:31 PM|LINK
Thanks, Bruce & Asteranup. That cleared it up. I should have thought of that.