How do I read a JSONP

Get help using Construct 2

Post » Tue Jan 06, 2015 3:50 pm

Is that even possible?

For instance a service.php returns something like:

Code: Select all
callback({"id":1, "value":32, "name": "item1"})


How could I read it trough an AJAX object?


Thank you very much!
B
4
Posts: 2
Reputation: 204

Post » Tue Jan 06, 2015 9:32 pm

To get the json response you can use the AJAX to request URL. This will trigger an event when it is finished. You can then get that JSON string response and do what you want with it. If you try to convert to an array, however, know that you JSON response must have a couple of extra tags at the beginning, something not in the documentation for the array.
B
5
Posts: 12
Reputation: 270

Post » Wed Jan 07, 2015 2:55 am

First of all, thanks for your answer jqquick223.


Can you please give me more details about those extra tags. I will really appreciate it.
B
4
Posts: 2
Reputation: 204

Post » Fri Jan 09, 2015 4:09 pm

You can try this demo out. https://www.scirra.com/tutorials/978/ex ... -game-card Open up his sample project and take a look at the CData2.json. HIs file more or less looks like this. Notice the first 3 lines. To add these things dynamically you would have to know the size of the incoming json array. I looked at trying to add these properties dynamically but struggled with it.

{
"c2array":true,
"size":[13,6,1],
"data":[[
...data...
]]
}
B
5
Posts: 12
Reputation: 270


Return to How do I....?

Who is online

Users browsing this forum: boybacteria, dop2000, Microbex and 29 guests