Use custom JSON to Array

1 favourites
  • 3 posts
From the Asset Store
Supports 1D, 2D, 3D arrays. Import and export arrays in JSON format
  • Hi,

    Very quick question, how would I be able to use thisJSON data in c2 easily if possible. I have tried using Hash table and no luck (doesn't help that it's not clear how to use that plugin). Using an ajax request btw.

    [
     {
      productid: 1,
      venueid: 1,
      categoryid: 4,
      product_name: "Name",
      product_desc: null,
      image_thumb_url: "URL",
      price: 10,
      tax_amount: 0,
      tax_included: true,
      in_stock: true,
      popularity: 0,
      product_modifiers: [{modifierid: 1, price: 1},{modifierid: 2, price: 1} ]},
     {
      productid: 2,
      venueid: 1,
      categoryid: 4,
      product_name: "NAME",
      product_desc: null,
      image_thumb_url: "URL",
      price: 15,
      tax_amount: 0,
      tax_included: true,
      in_stock: true,
      popularity: 0,
      product_modifiers: [{modifierid: 1, price: 1},{modifierid: 2, price: 1} ]
     }
    ]
    

    p.s. I can't change the JSON structure, just want to loop through these and store in array, and for the modifiers if possible to attached another array or c2 friendly json/string.

    Was hoping just to use hash table but so far i can't get anything useful from it, the example files don't help :(

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Construct 2 Arrays need the JSON files to be in a special format to load them as arrays. The format is

    {
         "c2array":true,
         "size":[
              2,
              13,
              1
         ],
         "data":[
              [
                  ?[1],
                  ?[1],
                  ?[4],
                  ?["Name"],
                  ?["null"],
                  ?["URL"],
                  ?[10],
                  ?[0],
                  ?["true"],
                  ?["true"],
                  ?[0],
                  ?[1],
                  ?[1]
              ],
              [
                  ?[2],
                  ?[1],
                  ?[4],
                  ?["Name"],
                  ?["null"],
                  ?["URL"],
                  ?[15],
                  ?[0],
                  ?["true"],
                  ?["true"],
                  ?[0],
                  ?[1],
                  ?[1]
              ],          
         ]
    }

    The first part must include the "c2array": true line, and then the next part is just the size of the array. You must include X, Y, and Z, even if it's just a 2D array, or else Construct 2 won't read it correctly.

    The last 2 elements are the product modifier prices that you seem to have as a subset under "product_modifiers". I excluded the price modifier IDs in the example as they seemed redundant, but yeah.

    That's how you'd do it if you wanted to import it into a Construct 2 Array object. Not sure how else you'd be able to accomplish it while keeping the format you have, though truthfully I don't see a need for you to hold onto it. Just make sure you have some documentation or notes on your project letting you know what each coordinate is for.

  • 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"]]]

    }

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