Parsing custom JSON with custom PHP

0 favourites
  • 3 posts
From the Asset Store
Paypal PHP Supports multiple platforms, Web/html5 Android, IOS. (Including storing transaction data)
  • Hi,

    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:

    scirra.com/forum/use-custom-jsOn-to-array_topic66542.html

    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):

    <?php
    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.

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

    <img src="https://dl.dropboxusercontent.com/u/29061450/construct2/array_data.jpg" border="0">

    Here's the capx.

    Almost there I think...

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • 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.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)