-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
org.json.JSONException: JSON does not allow non-finite numbers #385
Comments
this test passes: /**
* see https://github.com/stleary/JSON-java/issues/385
*/
@Test
public void testNumberConversion() {
String xmlStr = "<dataId dt:dt=\"string\">a98b174b86b54d7bb007d665382821d3</dataId>";
JSONObject jsonObject = XML.toJSONObject(xmlStr);
assertTrue("jsonObject should not be empty", jsonObject.length() != 0);
assertNotNull(jsonObject.optJSONObject("dataId"));
assertEquals("string",jsonObject.getJSONObject("dataId").optString("dt:dt"));
assertEquals("a98b174b86b54d7bb007d665382821d3",jsonObject.getJSONObject("dataId")
.optString("content"));
} Are you sure that is the section of your document that is causing the problem? |
Yes, you are right. It works with this string. Do you know what kind of input might possibly throw this exception? I have about 1 million XML files that have these kinds of strings. I am finding it hard to tell what is causing this issue. |
It would be something that causes under or overflow of a To parse all values as strings and post-process them, you should install call the XML parser like this: /**
* see https://github.com/stleary/JSON-java/issues/385
*/
@Test
public void testNumberConversion2() {
String xmlStr = "<dataId dt:dt=\"string\">a98b174b86b54d7bb007d665382821d3</dataId>";
JSONObject jsonObject = XML.toJSONObject(xmlStr, true);
assertTrue("jsonObject should not be empty", jsonObject.length() != 0);
assertNotNull(jsonObject.optJSONObject("dataId"));
assertEquals("string",jsonObject.getJSONObject("dataId").optString("dt:dt"));
assertEquals("a98b174b86b54d7bb007d665382821d3",jsonObject.getJSONObject("dataId")
.optString("content"));
} note the second parameter is <root>
<data>5</data>
<data>true</data>
</root> your processed JSON would look like: {
"root" : {
"data" : [{
"content" : "5"
}, {
"content" : "true"
}]
}
} |
Following is my code snippet Following is my stack trace: Do you know which library or version of jar file I need to use? |
This has been in the library since the 20160807 release. Did you compile your own version, or did you download from Maven? The maven builds are located here: https://search.maven.org/#search%7Cgav%7C1%7Cg%3A%22org.json%22%20AND%20a%3A%22json%22 Also make sure that no other dependencies in your project have an older copy of the JSON library. |
Yes, it looks like I had an older copy of the JSON present in the project. So, I updated it to the latest version of jar file : json-20171018.jar and it worked!! Thank you. |
you are welcome. |
I have the following section in my XML document:
<dataId dt:dt="string">a98b174b86b54d7bb007d665382821d3</dataId>
and I am using the jar file json-20171018 for converting the XML document to JSON.
I am getting the following error:
org.json.JSONException: JSON does not allow non-finite numbers.
at org.json.JSONObject.testValidity(JSONObject.java:1261)
It has been told that it has been fixed, but I am getting the same error. Is there any workaround for this?
#27
The text was updated successfully, but these errors were encountered: