user5489618
user5489618

Reputation: 17

XML to JSON object converting string to scientific notation

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.

Upvotes: 0

Views: 1260

Answers (1)

Michael Kay
Michael Kay

Reputation: 163458

Have you tried calling toJSONObject(java.lang.String string, boolean keepStrings) with the second argument set to true?

Upvotes: 2

Related Questions