Insert array of json data into json file using javascript & JSP -
i have 1 function in code gives me x & y coordinates. have formatted data , saved data array in json format. now, want save variable data json file. can me out this? variable arraydata contains string of json data want save new json file. or can use jsp save data json file? problem here is, data in javascript variable.
game.input.ondown.add(function() { x = math.floor(game.input.activepointer.worldx / 15); y = math.floor(game.input.activepointer.worldy / 15); arraydata.push("{'x':'" + x+"','y':'"+y+"'}"); document.getelementbyid('test').innerhtml = ' data: {"x":' + x+',"y":'+y+'}'; console.log(" data: " + arraydata); });
you don't have put object between quotes: string. change:
arraydata.push("{'x':'" + x+"','y':'"+y+"'}");
to:
arraydata.push({'x': x,'y': y});
which equivalent to:
var obj = { 'x': math.floor(game.input.activepointer.worldx / 15), 'y': math.floor(game.input.activepointer.worldy / 15) }; arraydata.push(obj);
Comments
Post a Comment