JSONObject: int values as key doesn't work properly

Post here your questions about Actionscript and Java server side extensions development.

Moderators: Lapo, Bax

Post Reply
BigFIsh
Posts: 1698
Joined: 25 Feb 2008, 19:26
Location: New Zealand

JSONObject: int values as key doesn't work properly

Post by BigFIsh »

Just something to keep in mind:

Code: Select all

JSONObject test = new JSONObject();
int userId = 10;
test.put(userId, "hello");
trace("Result: " + test.containsKey(userId));
Result traces out false. Same problem will occur for test.get(userId). However, if you send the 'test' JSONObject back to client, the data is there which took me a while to narrow down the problem.

Code: Select all

JSONObject test = new JSONObject();
int userId = 10;
test.put(userId, "hello");
trace("Result: " + test.containsKey(String.valueOf(userId)));
Result now traces out true. Casting the userId as String is the workaround.
Smartfox's forum is my daily newspaper.
Post Reply