leonardo
Posts: 0
Joined: Thu Mar 14, 2013 7:04 pm

Accessing Data from Json Object

Very new to using JSON and using these 2 data sets:
{
"myNames" [
{"name": "Name 1","index": 0},
{"name": "Name 2","index": 1}
]
}

{
"myDetails" [
{"name": "Name 1","story":This is 1's story"},
{"name": "Name 2","story":This is 2's story"}
]
}

var count = data.myNames.length; //valid and gives 2
var nam=data.myNames[1].name //gives Name 2

  1. It seems that the data is treated as an Array. I've seen where the JSON data is implicitly declared as an array, but this is not. Is there an advantage to this and would the data declared as an array still go into the Echo?
  2. I use the data from myNames for a list which is used to get the relevant data from myDetails. The data in myNames is sorted but the data in myDetails is not. In the list grid click JS I have:
    codevar getname=$(this).text();/code
    Is there a fast way to extract the relevant data in myDetails?
maxkatz
Posts: 0
Joined: Fri Aug 13, 2010 3:24 pm

Accessing Data from Json Object

Any valid JSON can be set in Echo.

To access any data in JSON array, there are JS functions/methods to traverse the JSON that you should use.

leonardo
Posts: 0
Joined: Thu Mar 14, 2013 7:04 pm

Accessing Data from Json Object

Can you point me to examples of this. I've searched and haven't found what fits my needs as described above.

leonardo
Posts: 0
Joined: Thu Mar 14, 2013 7:04 pm

Accessing Data from Json Object

codeTo access any data in JSON array, there are JS functions/methods to traverse the JSON that you should use./code

Do implicitly array go into the Echo too?

codeTo access any data in JSON array, there are JS functions/methods to traverse the JSON that you should use./code

Can you point me to examples of those functions and methods traversing JSON array. That's what I've been looking for.

maxkatz
Posts: 0
Joined: Fri Aug 13, 2010 3:24 pm

Accessing Data from Json Object

You can place any valid JSON as Echo.

I don't have links of the top of my head -- you can search and should be able to find many resources online.

Return to “Issues”