【问题标题】:Issue with boolean during conversion Xml to Json将 Xml 转换为 Json 期间的布尔值问题
【发布时间】:2016-10-21 11:06:53
【问题描述】:

我正在使用此代码 (org.json) 将 XML 转换为 JSON:

String xml = "...<field>TRUE</field>...";
JSONObject response = XML.toJSONObject(xml); 
response.toString(); // "field": true
// but I need "field": TRUE as in xml

问题是我不想将“TRUE”转换为布尔值。我需要将所有字段都转换为字符串。

【问题讨论】:

标签: java json xml


【解决方案1】:

使用keepStrings=false 参数。见here

keepStrings If true, then values will
not be coerced into boolean or numeric values and will instead be left as strings

【讨论】:

  • 提到的链接说 404 not found
猜你喜欢
  • 1970-01-01
  • 2013-03-09
  • 1970-01-01
  • 2021-08-30
  • 1970-01-01
  • 2022-01-22
  • 1970-01-01
  • 1970-01-01
  • 2016-04-27
相关资源
最近更新 更多