0

I'm using a program to build game levels with Box2D through exported JSON files but am having trouble with certain elements in the JSON file that tend to have multiple formats.

One "body" element for example has the position property that consists of an x and a y value:

"position" : 
{
     "x" : 0,
     "y" : 0
 },

Then later in the file another element has the position property that has no x or y, only a single number value:

"position" : 0,

I've tried things akin to if(element is Number || element is Object) to no success.

4

1 に答える 1

2

You can test the Object.constructor property:

Object(0).constructor == Number // true
Object(0).constructor != Object // true
{x:0, y:0}.constructor == Object // true
{x:0, y:0}.constructor != Number // true
于 2013-03-25T12:56:33.070 に答える