How do I format JSON in a way Construct 2 understands?

Get help using Construct 2

Post » Sun Jan 24, 2016 4:45 pm

Hello everyone,
it's been a long time since I've been back here but glad to be back at the same time. :) I've recently been playing around with Construct 2 in the hope of creating a very simple RPG mechanic. But, I hit a roadblock when I found that I couldn't seem to get C2 to respond to the JSON format that I was passing .

For example the following just wasn't getting me anywhere (as an array of objects):
Code: Select all
[{
   "id": "1",
   "string": "This is a string that belongs to the id of 1."
}, {
   "id": "2",
   "string": "This is another string that belongs to the id of 2."
}]


After some searching I found a couple of examples, so I could probably work with those. But I have a couple of questions, one being, why does Construct require a special format when it comes to JSON exactly? Or, is it the simple case that I'm just not doing it right by loading as Ajax and parsing it in to an array or dictionary?

And secondly, is there some form of reference in the manual that I've overlooked that goes in to detail about it?

My apologies if I've overlooked the obvious, but I'm not having too much luck and wondered if anyone else had a similar issue.

Thanks!
B
5
Posts: 22
Reputation: 283

Post » Sun Jan 24, 2016 5:09 pm

The easiest way to figure out C2's format is to mock up a few elements, and look at the JSON text. Once you see the pattern, then you can build your own data format and it will work.
ImageImageImage
B
71
S
20
G
202
Posts: 3,572
Reputation: 114,428

Post » Sun Jan 24, 2016 10:54 pm

Ah that's a good idea actually. Thank you! I take it construct has its own special format due to the fact it needs to work on many different devices? Or is it just simply the way it's written?
B
5
Posts: 22
Reputation: 283

Post » Sun Jan 24, 2016 11:12 pm

The format wasn't meant to be modified by hand. It's just an easy way to save the data by string and load it back again. It also always has to save a 3D array, so it gets complicated formatting three dimensions of data.
ImageImageImage
B
71
S
20
G
202
Posts: 3,572
Reputation: 114,428

Post » Mon Jan 25, 2016 1:50 pm

Ah I see what you mean. Thanks very much for clarifying!
B
5
Posts: 22
Reputation: 283


Return to How do I....?

Who is online

Users browsing this forum: ephrisian, kiugetski and 8 guests