-2

After parsing an object the string values are automatically changed to double values. Any workaround for the same

JSONObject elementInfo = obj.getElementInfo();
System.out.println("get elementInfo ---> "+elementInfo.get("info"));

//mapping
ArrayList<Object> getEle = gson.fromJson((String) elementInfo.get("info"), ArrayList.class);
System.out.println("After mapping getele----> "+getEle);

Result

get elementInfo ---> [{noOfBins=2, indices=[1, 3]}, {noOfBins=3, indices=[2]}]
After mapping getele----> [{noOfBins=2.0, indices=[1.0, 3.0]}, {noOfBins=3.0, indices=[2.0]}]

Even after mapping how will I get the exact value? Need to get it as

[{noOfBins=2, indices=[1, 3]}, {noOfBins=3, indices=[2]}]
Wasi Ahmad
  • 35,739
  • 32
  • 114
  • 161
USB
  • 6,019
  • 15
  • 62
  • 93
  • I don't see any String in your `elementInfo` Json. A String in JSON is like `"2"` or `'2'`, without the quotes, this is a numeric – AxelH Dec 30 '16 at 06:43

1 Answers1

1

In JSON, string shoubld be contained in double quotes, that means "4" instead of 4 .

Claim Yang
  • 309
  • 1
  • 9