Reputation: 2417
I have:
String example = {"test":"true"}
but I want to have:
example = {"test":true}
How can I convert the first string to the second?
Upvotes: 2
Views: 5025
Reputation: 1
If you want it done right, then you need to make sure to take care of other conditions in the json data. Assuming parse_data is 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);
Upvotes: 0
Reputation: 137382
You can use String result = example.replaceAll(":\"true\"", ":true"};
and String result = example.replaceAll(":\"false\"", ":false"};
if there are only boolean values.
Upvotes: 1