Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

XML.toJSONObject interprets certain strings as infinite numbers #27

Closed
bachp opened this issue Oct 8, 2011 · 4 comments
Closed

XML.toJSONObject interprets certain strings as infinite numbers #27

bachp opened this issue Oct 8, 2011 · 4 comments

Comments

@bachp
Copy link

bachp commented Oct 8, 2011

Take the following XML snippet as an example.

<?xml version="1.0" encoding="UTF-8"?>
<subsonic-response xmlns="http://subsonic.org/restapi" status="ok" version="1.6.0">
  <playlists>
    <playlist id="476c65652e6d3375" name="Mood"/>
    <playlist id="50617274792e78737066" name="Party"/>
  </playlists>
</subsonic-response>

the playlist elements have id's that are hexadecimal strings.

in <playlist id="50617274792e78737066" name="Party"/> the id can also be interpreted as an exponential number. This makes the conversion of this snippet fail with the message: org.json.JSONException: JSON does not allow non-finite numbers

I don't know if there is a way to tell the difference between a number and a string from XML but I think the problem could be avoided if instead of throwing an exception the implementation interprets the infinite number as a string in any case.

@bachp
Copy link
Author

bachp commented Oct 8, 2011

I just realized that I used an older version of XML.toJSONObject that still uses the JSONObject.stringToValue instead of XML.stringToValue.

Probably this problem is already fixed with the newer version.

@douglascrockford
Copy link
Contributor

Thanks. Please try it now.

@sivaramansv
Copy link

I have the following section in my XML document:
a98b174b86b54d7bb007d665382821d3
and I am using the jar file json-20171018 for converting the XML document to JSON.

I am getting the exact same error. How did you fix this?
org.json.JSONException: JSON does not allow non-finite numbers.
at org.json.JSONObject.testValidity(JSONObject.java:1261)

@johnjaylward
Copy link
Contributor

Please open a new issue with a fresh example. Preferably include the actual XML that is causing the problem, or at a minimum, a subsection of the XML that exhibits the problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants