Loading JSON into array

Bugs will be moved here once resolved.

Post » Thu May 17, 2012 5:36 am

Apologies if this is user error but have tried this with a variety of JSON files and nothing is loading into the array properly. Clearly the AJAX request is fine but then the "Load from JSON string AJAX.LastData" doesn't properly convert the JSON to array...

http://dl.dropbox.com/u/27776377/JSON.capx

Thanks for any help!
Aaron
B
4
Posts: 6
Reputation: 487

Post » Thu May 17, 2012 3:04 pm

Firstly, the JSON snippet you have used is more like a dictionary map than an array. It's not a sequence of elements, it's associating "success" with "true", and so on. This is a better fit for the Dictionary plugin which is coming in the next beta.

Secondly your JSON must be in a special format for Construct 2 - look at the value returned from Array's AsJSON expression for a 1 x 1 x 1 array:

[code]{
    "c2array": true,
    "size": [1,1,1],
    "data":[[[0]]]
}[/code]

Your JSON must also match this format for Array. It's designed to only be used with JSON returned from other Array objects.
Scirra Founder
B
359
S
214
G
72
Posts: 22,949
Reputation: 178,554

Post » Sat May 19, 2012 10:43 pm

Thanks Ashley, hugely useful!
B
4
Posts: 6
Reputation: 487

Post » Mon Jul 02, 2012 4:26 am

I want to add a note here (and I have to thank Ashley's above clarification for the hour or so I spent deriving this solution), but if you're loading a JSON object from a server, you'll want to make sure it's a 3-dimensional array, and that, for example --and this was my issue-- if you have a 2-dimensional array, you'll have to set it up as a 3-dimensional array anyway with all entries set on 0z. (E.g [123][45][0] in php will serialize correctly with json_encode() as opposed to [123][45]. Similarly, for a 1d array, you'll have to place all entries on the 0y 0z plane. mucks2012-07-02 04:27:43
B
3
Posts: 1
Reputation: 327

Post » Thu Jul 05, 2012 2:51 am

Good point mucks! Cheers!
B
4
Posts: 6
Reputation: 487

Post » Tue Apr 07, 2015 4:32 am

Hi,

Facing same kind of problem, can you please put some example to to display data for particular position
Below is my received json data
{
"c2array":true,
"size":[6,4,1],
"data":[
[[4837],["test2"],[2],["1"]],
[[700],["test6"],[6],["5"]],
[[600],["test1"],[1],["4"]],
[[30],["test1"],[1],["3"]],
[[10],["test1"],[1],["1"]],
[[10],["test1"],[1],["2"]]]
}
B
3
Posts: 6
Reputation: 187

Post » Tue Apr 07, 2015 7:25 am

@dapankaj

This is a 3 year old closed bug report you have pointlessly bumped with what is just a 'How Do I' type question.

You should probably post such a question in the correct part of the forum, if you hope to get a good response.
If your vision so exceeds your ability, then look to something closer.
Moderator
B
120
S
28
G
68
Posts: 4,844
Reputation: 48,289

Post » Tue Apr 07, 2015 7:54 am

@zenox98,
Apologies,,

And thnx for your response, can you please suggest correct part of the forum,so that i can post.
Because l am confused with this question thread is coming from ?
Yesterday i had posted one question ( www . scirra .com / forum/ viewtopic.php?f=147&t=128374) Correct me if that one belongs to wrong part of forum
Cannot insert link here


Thank you
B
3
Posts: 6
Reputation: 187


Return to Closed bugs

Who is online

Users browsing this forum: No registered users and 4 guests