Bachalo
Bachalo

Reputation: 7219

AS3 convert a nested array to JSON object

There is the native JSON.stringify method, but this is NOT what I need

I need to convert the following

[['user1',150],['user2',270],['user3',500]]

to a proper JSON object

{"user1" : 150,
"user2" : 270,
"user3" : 500
}

Upvotes: 1

Views: 2299

Answers (1)

Bachalo
Bachalo

Reputation: 7219

ok answering my own question

var jsonOb={}


var L:int=testArray.length;

for(var i:int=0;i<L;i++){

    jsonOb[testArray[i][0]]=testArray[i][1]

}




trace('jsonOb=='+jsonOb+ ' and JSON.stringify(jsonOb) = '+JSON.stringify(jsonOb));

Upvotes: 1

Related Questions