Use custom JSON to Array

Get help using Construct 2

Post » Wed Apr 17, 2013 10:27 pm

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.

[code]
[
{
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} ]
}
]
[/code]

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 :(
B
24
S
11
G
5
Posts: 140
Reputation: 5,004

Post » Thu Apr 18, 2013 12:39 am

Construct 2 Arrays need the JSON files to be in a special format to load them as arrays. The format is
[code]{
     "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]
          ],          
     ]
}[/code]
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.TL222013-04-18 00:43:24
B
58
S
20
G
7
Posts: 305
Reputation: 8,804

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


Return to How do I....?

Who is online

Users browsing this forum: Magistross, zatyka and 20 guests