Page 6 of 6

Echo Response Truncated

Posted: Tue Jun 25, 2013 3:16 pm
by leonardo

Okay, I got the JSON validated and can now display the names. But I'm still bogged down with my second question: How to traverse the JSON containing the detail data, find the record, and get the data with
a) 1 RESTService with two JSON objects (myNames and myDetails)
b) 2 RESTServices: with a JSON object placed in each service
Examples would be appreciated.

code{
"myNames" [
{"name": "Name 1","index": 0},
{"name": "Name 2","index": 1}
]
}

{
"myDetails" [
{"name": "Name 1","story":......"},
{"name": "Name 2","story":......"}
]
}
/code


Echo Response Truncated

Posted: Tue Jun 25, 2013 5:48 pm
by maxkatz

You should search online for an example - you should be able to find plenty of examples of how to traverse JSON with JavaScript.


Echo Response Truncated

Posted: Tue Jun 25, 2013 6:46 pm
by leonardo

Yep, I am actually doing that. My problem is how to connect the two JSON objects from Appery REST.


Echo Response Truncated

Posted: Tue Jun 25, 2013 7:29 pm
by maxkatz

You can get the entire JSON via service's 'success' event.


Echo Response Truncated

Posted: Tue Jul 02, 2013 3:17 pm
by leonardo

No resolution to this problem. I have the 2 Json data validated and put in RESTservice1 and RESTservice3. I have the following applied:

code<b>On StartPage Restservice1 Success<&#47;b>:
var count = data&#46;pnames&#46;length;
alert("count: " + count); &#47;&#47;Works as expected

<b>On StartPage Restservice3 Success<&#47;b>:
var countb=data&#46;pdetail&#46;length;
alert("detail count: " + countb); &#47;&#47;hangs and gives nothing
/code
Simply, where and how would I connect more than 1 RestServices?


Echo Response Truncated

Posted: Tue Jul 02, 2013 6:52 pm
by Kateryna Grynko

Hi Leonardo,

Create two services. The first one is for item list. The second one is for selected item content.


Echo Response Truncated

Posted: Tue Jul 02, 2013 7:17 pm
by leonardo

codeCreate two services&#46; The first one is for item list&#46; The second one is for selected item content&#46;/code

Katya, that's exactly what I did, but as shown above cannot access it from the service success, as I thought I would and as was pointed out earlier.

I've been going back and forth for weeks on this seemingly simple thing. Is it possible to know exactly how I can access the data? I've referenced it as "data.pdetail" and also "window.pdetail" all to no avail. How should I reference it?The project called "Opi" is still shared.


Echo Response Truncated

Posted: Tue Jul 02, 2013 9:17 pm
by Kateryna Grynko

Services for getting content won't help. You also haven't converted XML with content to JSON.
You would need to convert content to JSON and place it in usual JavaScript files where access needed item by array index.


Echo Response Truncated

Posted: Tue Jul 02, 2013 10:15 pm
by leonardo

Katya. Thanks so much for pointing me to JSON. It is very easy to use once the data is validated. (BTW, I converted the XML to JSON, but left it in Echo just for testing and comparison purposes).
In case it might help someone else, this is the process that I used:
code
1&#46; Create a validated JSON
2&#46; Copy it and paste into a new Javascript in Appery
3&#46; Declare the javascript as a variable
4&#46; Access it like a normal js array&#46;
/code