Parsing custom JSON with custom PHP

Get help using Construct 2

Post » Tue Jan 14, 2014 2:08 am


I've been working with C2 for a couple weeks now. Yesterday I ran into an issue trying to parse a JSON file into an array. It works fine with the Dictionary object, but I don't seem to be able to get the formatting right with an Array. Now, I already read through this thread:

But I'm not trying to parse "pure" JSON and I have access and ability to modify the JSON file. Here's the code I'm using (with some irrelevant data):

header("Access-Control-Allow-Origin: *");

$name = 'Ainx';
$level = 3;
$experience = 56;
$gold = 244;

//Build 2nd dimension
$arr_names = array('name' => $name);
$arr_levels = array('level' => $level);
$arr_experiences = array('experience' => $experience);
$arr_golds = array('gold' => $gold);

//Build 1st dimension
$arr_data = array($arr_names, $arr_levels, $arr_experiences, $arr_golds);

//Build c2array
$arr = array('c2array' => TRUE, 'size' => array(4, 2, 1), 'data' => $arr7);

echo json_encode($arr);

The code prints fine and I can parse and retrieve it with .getAjax and so on... I can also retrieve that in C2, but when I try to put it into a C2 array, it does nothing. Am I building this array incorrectly? I included C2 specific tags.

Here's the example php file above.

Using a dictionary works:

$dic_data = array('name' => $name, 'level' => $level, 'experience' => $experience, 'gold' => $gold);
$dic = array('c2dictionary' => TRUE, 'data' => $dic_data);

I'm able to import that into a dictionary in C2 without a hitch, but I'd like to be able to use arrays, because Dictionary is a tad too primitive for what I need. I thought about using two Dictionaries instead when I couldn't get the array to work, but that's a bit silly...

I'm using the AJAX Request, AJAX On completed and Array Load events; all the basic AJAX/Array stuff covered in the tutorials and the manual on the site. I think the issue is with how I'm formatting PHP which now that I think about it might not be for this forum :<

Any help would be appreciated.
Posts: 29
Reputation: 581

Post » Tue Jan 14, 2014 3:57 am

After a bit more tinkering I was able to import the json into an array without Construct 2 exploding. However, now I have this:

Here's the capx.

Almost there I think...
Posts: 29
Reputation: 581

Post » Thu Oct 16, 2014 2:23 am

I'm trying to figure this out too. I'm not sure what the correct php syntax is for formatting the json_encode() so that I can scoop it up into a C2 dictionary object.
Posts: 33
Reputation: 612

Return to How do I....?

Who is online

Users browsing this forum: dop2000, gonzdevour and 38 guests