0

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?

Community
  • 1
  • 1

1 Answers1

2

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?
Community
  • 1
  • 1
Woodrow
  • 2,740
  • 1
  • 14
  • 18