how to load json in construct2 variable or text

0 favourites
  • 7 posts
From the Asset Store
It is a powerful and complete package containing a total of 20 enemy AI mechanics.
  • i am a newbee in construct2 ...I have made a php page that returns me json string like below


    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 " "&

    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.

  • 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!

  • 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???

  • 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

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • 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.

  • Thanks Kyatric , it make lot of since now ...i am able to use dictionary and array from json because of your help. Thanks again,

  • Kyatric

    Thanks for the link to the FAQ, never seen it before. Some real gems in there <img src="smileys/smiley1.gif" border="0" align="middle" />

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)