Dorian McAllister
Dorian McAllister

Reputation: 785

XML to JSON convertor

Was looking at a few questions in SO for a good solution for XML to JSON convertors. I Chanced upon this : Convert xml to json with Java This seemed to work fine for almost all of our scenarios but for the issue below! I noticed whenever I we have an XML such as this (zero followed by a number)

<a>011</a>

this seems to be getting formatted to

{a:9}

However this seems to work fine

<a>11</a>

Whcih gets formatted to

{a:11}

This is the simple code I am using:

String sXML = "<a>011</a>";
JSONObject xmlJSONObj = XML.toJSONObject(sXML);

Any pointers?

Upvotes: 0

Views: 94

Answers (1)

Woodrow
Woodrow

Reputation: 2832

Looks like it thinks it's an octal value, which is why you get 9, see the following article which has a similar problem:

  1. How to force php to evaluate "011" as "11" and not "9"
  2. When displaying the value of variable "int a = 011", I get 9. Why?

Upvotes: 2

Related Questions