问题描述:

I am using html and JSON. What I am doing is creating levels for a game in JSON and parsing information in javascript.

I have no problem doing this when the information is an integer. I will simply right the following for example:

 for (var i = 0; i < curNode.options.length; i ++) {

var x = parseInt(curNode.options[i].x);

var y = parseInt(curNode.options[i].y);

//set the positions

var choice = new Choice(scene);

choice.setPosition(x, y);

}

and so forth. I can do this with width, height etc but I am not sure how to do this when simply dealing with a string.

网友答案:

You can do type casting easily as follows:

var avariable = 3; var astring = avariable + ''; var anotherstring = new String(avariable);
相关阅读:
Top