I need to convert a string {\"name\":\"test name\", \"age\":25}
to a JSONObject
String message; JSONObject json = new JSONObject(); json. put("test1", "value1"); JSONObject jsonObj = new JSONObject(); jsonObj. put("id", 0); jsonObj. put("name", "testName"); json.
Perhaps I'm misunderstanding the question but it sounds like you are already using org.json which begs the question about why
val answer = JSONObject("""{"name":"test name", "age":25}""")
wouldn't be the best way to do it? What was wrong with the built in functionality of JSONObject?
val rootObject= JSONObject() rootObject.put("name","test name") rootObject.put("age","25")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With