JSON Syntax

Get help using Construct 2

Post » Tue Jan 07, 2014 4:31 pm

Hello everyone,

I'm trying to transfer a JSON file into an array, I've read many forum posts about this but it seems I'm missing something.

1. On user click AJAX request JSON project file
2. Array load JSON from AjaxLastData
3. Use first string to load image from URL and second string to display text

I may have a problem with the JSON syntax as it's the first time I use it but I have followed Ashley's instruction concerning the "c2array":true.


Here is the .CAPX, the JSON is in the project files.
JsonTest
B
8
S
3
G
2
Posts: 35
Reputation: 2,176

Post » Tue Jan 07, 2014 5:39 pm

Your JSON is misformed:

{"c2array":true,"size":[2,1,1],"data":[[["https://dl.dropboxusercontent.com/u/24624228/Fonction1/b1.jpg"]],[["This is text"]]]}

and arrays are 0-based, so your indexing should be .At(0) and .At(1) (you don't need to specify all dimensions for a one-dimensional array).
ImageImageImage
B
71
S
21
G
231
Posts: 3,694
Reputation: 129,364

Post » Tue Jan 07, 2014 6:52 pm

Thank you very much my good sir !
A fast answer with so many brackets ! :p

The syntax seems good but when I run the layout I get this error :

"Javascript error!
Uncaught TypeRrror: Cannot read properly '0' of undefined
http://localhost:50000/arr_plugin.js, line 139 (col 17)

This is either a bug in Construct 2 or a problem in a third party
plugin or behavior - please report it to the developer !"

Do you have any clue about this ?

Here's the updated project file :
https://drive.google.com/file/d/0B-727M6ikDE_TWxWMFNYdUxWc1E/edit?usp=sharing
B
8
S
3
G
2
Posts: 35
Reputation: 2,176

Post » Tue Jan 07, 2014 7:14 pm

Must be formatting. If I use my text exactly, it works.
ImageImageImage
B
71
S
21
G
231
Posts: 3,694
Reputation: 129,364

Post » Wed Jan 08, 2014 11:26 pm

My bad, it works with your text.

Thanks a lot !
B
8
S
3
G
2
Posts: 35
Reputation: 2,176


Return to How do I....?

Who is online

Users browsing this forum: evillair, lordsas, Matei511, tarek2 and 64 guests