Parse JSON string to object array
h
mwilki7 (147)

I'm attempting to turn an existing array into a json string so that this string can be saved for loading and saving levels in my game.

But when I parse the json string back into my array I get
entlist[i].draw is not a function
which leads me to believe the json to object didn't work properly.

Does anyone know how to do object -> json -> object conversions properly?
I want to be able to able to call the same member functions these objects had before they were converted.

function save()
{
    var jsonstring = JSON.stringify(entlist);
    $("#leveldata_textarea").val(''); // dont want any garbage that may have made its way in here
    $("#leveldata_textarea").val(jsonstring);
}
function load()
{
    var jsonstring = $("#leveldata_textarea").val();
    entlist = JSON.parse(jsonstring);
    console.log(entlist);
}

This image is a before-and-after snapshot of my array before json conversion and after.

You are viewing a single comment. View All
Answered by malvoliothegood (107) [earned 5 cycles]
View Answer
mwilki7 (147)

@malvoliothegood Shame. Though it would probably be a lot more text than would be necessary. I decided to use a text area to store the necessary elements along with the classname as the header.

Thanks for answering.