JSON to array or dictionary

0 favourites
  • 5 posts
From the Asset Store
Supports 1D, 2D, 3D arrays. Import and export arrays in JSON format
  • Hello,

    On my plugin, I have an array and I want to return it from a function as json to be able to load it into an array object and I want to do the same for a dictionary.

    I've been trying for a while and can't make it work, anyone has a working example I can follow?

    I do know it needs specific syntax (from google searching - I can;t seem to find this info on the documentation) but it still fails.

    Code example that is failing:

    Listinventory()
    {
     	var width = 2;
     	var height = 1;
     	var c2ArrayData = ["cat","dog"]
     	
     	
     	var c2Array = '{"c2array":true,"size":[' + width + ',' + height + ',1],"data":' 
     	+ JSON.stringify(c2ArrayData) + ",[],[]}";
    
    	return c2Array;
    }
    

    This returns: {"c2array":true,"size":[2,1,1],"data":["cat","dog"],[],[]} but I can't seem to load it into an array.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • The easiest way to get the format is to create the array example in C3 first, and use AsJSON to see what it looks like. This is what I get:

    {"c2array":true,"size":[2,1,1],"data":[[["cat"]],[["dog"]]]}

  • Thank you for the reply blackhornet, I actually tried the asJSON but the json I'm getting has empty data.

    I'm trying to set it as text on a text object to debug, maybe thats the problem?

    How are you getting it?

  • That caught me by surprise too, but it's the Text object trying to interpret BBcodes - there is a property to turn that off! Or, use a Text Input object, which lets you copy the text anyway, which is what I did.

  • Completely missed the BBcode thing - thanks a mil, I've got it all working now !

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