Page 1 of 1

Accessing Data from Json Object

Posted: Wed Jun 26, 2013 7:18 pm
by leonardo

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?

Accessing Data from Json Object

Posted: Wed Jun 26, 2013 8:00 pm
by maxkatz

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.


Accessing Data from Json Object

Posted: Wed Jun 26, 2013 8:31 pm
by leonardo

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


Accessing Data from Json Object

Posted: Wed Jun 26, 2013 8:36 pm
by leonardo

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.


Accessing Data from Json Object

Posted: Wed Jun 26, 2013 8:46 pm
by maxkatz

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.