i am using org.json to convert a big xml to a json string. however it seems that for the number 0 it creates a string "0", while other numbers like 5 or 2 work fine and become real numbers.
xml:
<w count="2" winline="5" freespins="0" jackpot="false" start="0" payout="500" supergames="0" />
java:
JSONObject json = XML.toJSONObject(xml);
String jsontext = json.toString();
resulting json:
"w":[{"supergames":"0","freespins":"0","winline":5,"count":2,"start":"0","jackpot":false,"payout":500}
is there any way to make the 0 become real 0-numbers instead of strings?
Looks like a bug. I looked at the source and it looks like it may throw
IndexOutOfBoundsException
, which basically resulting in a failed conversion to a number:https://github.com/douglascrockford/JSON-java/blob/master/XML.java (line 327):
Throws if string starts with "0" and is only 1 character long, i.e. if the string is "0". The exception is caught and the conversion method basically just returns the original string ("0") again unconverted.
Not many options:
0.0
in lieu of0
, then munge the "0"'s in the XML to be "0.0"'s. (credit @bestsss)