jdon pluhin -- example that doesnt work well

0 favourites
  • 9 posts
From the Asset Store
Unlock platyers earning coins, and save it with Localstorage
  • Hi,

    Below is a sample that doesnt seem to parse correctly.

    dropbox.com/s/apzz8j7qw4t3nl0/jsonSample.c3p

    if you can look at it,

    thank you,

    Daniel

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • grossd

    Here is a new copy of the file you sent to me. I got it working the way I think you want, updating an actual list box. I used the JsonManager loop instead of the built in array object. It looks like it works well, if you have any question, just let me know.

    https://www.dropbox.com/s/m2lxy0ppsjlgdmt/jsonSample%20%283%29.c3p?dl=0

  • thank you!

    this is very educational example, how to use the constructs together.

  • grossd

    No problem. If you have any questions about how it works, just let me know

  • Hi,

    Could i ask you how the loop would be changed if i am downloading a table rather than a column only. Something like below.

    Now, i would want to show Str1 to Str4 in the listbox, while storing in a dictionary Str1 ... Str4 as keys with the numbers "1" to "4" as the values ...

    (i.e. a mapping from the strings to their respective identifiers

    I tried to add the accessor [0] of [1], such as: trim(JsonManager.GetJsonValue("","[1]","Yes")), to access the strings, when building the listbox, but this didn't work.

    thank you!

    Daniel

    {

    "range": "Sheet1!A4:B7",

    "majorDimension": "ROWS",

    "values": [ [ "1", "Str1" ],

    [ "2", "Str2" ],

    [ "3", "Str3" ],

    [ "4", "Str4" ]

    ]

    }

  • I solved it in a somewhat cumbersome way:

    Since the loop apparently goes through all values in the table "breadth first" -- across each row, i added two subevents with condition 0 and 1, respectively. i then have a counter that "flip flops" between 0 and 1 (by adding one to a counter and then taking modulu 2).

    Like this each subevent "knows" what column it handles.

    But, i think its is pretty cumbersome and better if there is a simple way to access each column in a received row -- via a simple expression.

    can this be done

  • grossd

    I'll take a look and I'll get back to you with how to do that.

  • grossd

    I modified the sample so that it populates the list box and creates a dictionary from that new json structure you sent. It populates the text box with the dictionary.

    The Json structure with just arrays of data is not easy to parse like this even in javascript. If the arrays contained objects that had properties it would be a little easier to query. But with just arrays of strings you have to have a little knowledge of the structure to parse it. The example in the link below is the best way I can think to do it.

    I hope this helps

    https://www.dropbox.com/s/xzcykh9ab7032d3/jsonSample%20%284%29.c3p?dl=0

  • Hi,

    Yes!

    That is the approach I did as well. Just yours is much cleaner -- to use loop index (instead of a local variable) in the subevent to identify the column.

    great.

    thank you,

    Dan

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