How do I load json to array

Get help using Construct 2

Post » Sun Jan 17, 2016 2:06 pm

I written a php code where it will echo a json string like this
"{""c2array"":true,""size"":[3,1,1],""data"":[[[""user""]],[[100]],[[999]]]}"


My PHP code looks like this

Code: Select all
<?php header('Access-Control-Allow-Origin: *');
header('Content-Typer:application/json');

$username ="user";
$chips ="100";
$token ="999";


echo "\"{\"\"c2array\"\":true,\"\"size\"\":[3,1,1],\"\"data\"\":[[[\"\"".$username."\"\"]],[[".$chips."]],[[".$token."]]]}\"

"; 
?>


I requested with ajax to my URL
and then on complete I set array to load Json string from Ajax.LastData.
When I check it nothing happen to my array.

Help please
B
14
S
3
Posts: 57
Reputation: 884

Post » Sun Jan 17, 2016 5:43 pm

This is what you would use if you were pasting JSON into the event sheet.
Code: Select all
"{""c2array"":true,""size"":[3,1,1],""data"":[[[""user""]],[[100]],[[999]]]}"


When loading through AJAX you don't need to escape the quotation marks so it should look like:
Code: Select all
{"c2array":true, "size":[3,1,1], "data":[[["user"]],[[100]],[[999]]]}
B
55
S
28
G
18
Posts: 1,520
Reputation: 25,305


Return to How do I....?

Who is online

Users browsing this forum: JoshVillaluz, KittenKatja, LaDestitute, ladjuric, Zjahel0001 and 9 guests