• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Help with save JSON

H

hiep

Guest
I have use JSON to save but i dont know how to save a array into a JSON please help me .

this is my all code save and load the JSON
Code:
var list = ds_list_create();
var feat = ds_list_create();

with (Obj_Undo)
{
    var _map = ds_map_create();
    ds_list_add(list, _map);
    ds_list_mark_as_map(list, ds_list_size(list) - 1);

    ds_list_copy(feat, fea_list);
    ds_map_add_list(_map, "fea", feat);
}
var    wrapper = ds_map_create();
ds_map_add_list(wrapper, "root", list);
var json = json_encode(wrapper);
ds_map_destroy(wrapper);
I store array into fea[| 0]

Code:
    var feat = ds_list_create();
    with (Obj_Undo) instance_destroy();
   
    var _wrapper = ds_stack_pop(global.Undo_stack);
   
    _wrapper = json_decode(_wrapper);
    var list = _wrapper[? "root"];
   
    for (var i = 0; i < ds_list_size(list); i++)
    {   
        var map = list[| i];
      
        with (instance_create_layer(0, 0, layer, asset_get_index(obj)))
        {
            ds_list_copy(feat, map[? "fea"]);
            var featt = array_create(6, false);
            featt = feat[| 0];
        }
    }
    ds_map_destroy(_wrapper);
    ds_list_destroy(list);
}
Thanks for your advance !
 

The-any-Key

Member
You need to serialise the array to a string or use a map with a list in it instead and use ds_list_mark_as_map on the map with the list in it (that you used ds_map_add_list with the list)
I don't think there is a ds_list_add_list so this is a workaround.
 
Top