Issue
In my case one of the xml tag value is "09031454866678e6". While converting to json object e in the is considered as scientific notation and converting into "9.031454866678E6".
How should I avoid this conversion and ensure that it is parsed as a string and not a number?
In code:
JSONObject xmlJSONObj = XML.toJSONObject(resp);
where resp is xml string.
it is failing while setting a value
listObject.setObjId(rootJObject.getString("abc"));
setobject method is as below
public void setObjId(String objId) {
this.objId = objId;
}
maven dependencies used in project is
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20180813</version>
</dependency>
I am expecting output to be the same as the original value, "09031454866678e6". It should not convert to scientific notification.
Solution
Have you tried calling toJSONObject(java.lang.String string, boolean keepStrings)
with the second argument set to true?
Answered By - Michael Kay
Answer Checked By - Mary Flores (JavaFixing Volunteer)