[英]How do I remove backslashes before quotes from a JSONObject string?
[英]How do I remove quotes from a boolean value in a JSON string?
我有:
String example = {"test":"true"}
但我想拥有:
example = {"test":true}
如何将第一个字符串转换为第二个字符串?
您可以使用String result = example.replaceAll(":\\"true\\"", ":true"};
和String result = example.replaceAll(":\\"false\\"", ":false"};
如果存在只是布尔值。
如果您希望正确完成操作,则需要确保照顾json数据中的其他条件。 假设parse_data是JSONObject(java)
String raw_tag = parse_data.toString();
raw_tag = raw_tag.replaceAll(":\"true\"", ":true");
raw_tag = raw_tag.replaceAll(",\"true\"", ",true");
raw_tag = raw_tag.replaceAll("\\[\"true\"", "\\[true");
raw_tag = raw_tag.replaceAll(":\"false\"", ":false");
raw_tag = raw_tag.replaceAll(",\"false\"", ",false");
raw_tag = raw_tag.replaceAll("\\[\"false\"", "\\[false");
System.out.print(parseData);
使用正则表达式和/或String类方法,例如'replaceAll'。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.