how to load json in construct2 variable or text

Discussion and feedback on Construct 2

Post » Sat Jan 25, 2014 10:08 pm

i am a newbee in construct2 ...I have made a php page that returns me json string like below

{"status":"failed","Code":"400000"}


the problem is i don't know how to extract the status and code from AJAX.LastData values. I have added Array object on my project and then i used following statement in thought that maybe i will get 0 element value but it displays nothing.

ajax (on completed) ->
    Array = Load from Json String ajax.LastData
    TextOut = Set Text to " "&Array.at(0)



Kindly tell me what mistake i am making in retriving the data ? if i dont use json then everything works fine but i need json to use.

B
9
S
2
Posts: 108
Reputation: 1,010

Post » Sun Jan 26, 2014 12:24 am

Thit is exactly as I have it and it works fine:

*EDIT: Sorry I can't get the image uploaded now and need to leave, sorry!

I think the issue is you haven't saved your data as an array in the first place. You would need to save your array as json, upload it, then when you download it again it will work.

But if you want to add your values into an array, just do something like:

Repeat tokencoun(ajax.lastdata,"(chosen token"))
Set value of array at index: loopindex to tokenat(ajax.lastdata,loopindex,token)

That should work fine, but I am still very new at this!Tobye2014-01-26 00:27:26
B
28
S
8
G
5
Posts: 429
Reputation: 7,007

Post » Sun Jan 26, 2014 12:07 pm

I am sorry i dont understand what you mean by saving array as json and upload it?

The lastData contain the json string do i need to save that in disk before parse it???
B
9
S
2
Posts: 108
Reputation: 1,010

Post » Mon Jan 27, 2014 7:21 am

i am still looking for a solution i cannot find any good help yet. Kindly anyone help me to read json from web page to construct2 array or variable..if is there a tutorial available then please share as well
B
9
S
2
Posts: 108
Reputation: 1,010

Post » Mon Jan 27, 2014 11:54 am

In the "how do I" forum you can find as sticky the How do I FAQ which contains some items in its "AJAX" section that are in direct relation to what you're looking for.

But also, as Tobye explained: fill your array in C2 and use the Download action from the array plugin. (be sure to check the Manual)
You'll then see that the format of your original string doesn't comply with the one from an array in C2.

Check this example capx that uses only 4 cells out of 10.
Such a string could then be correctly loaded in the array.Kyatric2014-01-27 11:54:40
New to Construct ? Where to start

Image Image

Image Image

Please attach a capx to any help request or bug report !
Moderator
B
292
S
115
G
96
Posts: 7,295
Reputation: 70,795

Post » Tue Jan 28, 2014 9:36 pm

Thanks Kyatric , it make lot of since now ...i am able to use dictionary and array from json because of your help. Thanks again,
B
9
S
2
Posts: 108
Reputation: 1,010

Post » Tue Jan 28, 2014 9:48 pm

@Kyatric

Thanks for the link to the FAQ, never seen it before. Some real gems in there
B
48
S
16
G
9
Posts: 1,098
Reputation: 11,197


Return to Construct 2 General

Who is online

Users browsing this forum: mihirolover and 10 guests