【问题标题】:string values are automatically changed to double values [duplicate]字符串值自动更改为双精度值 [重复]
【发布时间】:2017-05-14 11:52:21
【问题描述】:

解析对象后,字符串值会自动更改为双精度值。 任何相同的解决方法

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);

结果

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]}]

即使在映射之后,我将如何获得确切的值? 需要得到它作为

[{noOfBins=2, indices=[1, 3]}, {noOfBins=3, indices=[2]}]

【问题讨论】:

  • 我在您的elementInfo Json 中看不到任何字符串。 JSON 中的字符串类似于"2"'2',没有引号,这是一个数字

标签: java object arraylist gson


【解决方案1】:

在 JSON 中,字符串应该包含在双引号中,这意味着 "4" 而不是 4

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-10-06
    • 2014-01-06
    • 1970-01-01
    • 1970-01-01
    • 2023-04-01
    • 1970-01-01
    相关资源
    最近更新 更多