How to create a JSONObject from String in Kotlin?
I need to convert a string {\"name\":\"test name\", \"age\":25}
to a JSONObject
Solution 1:
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?
Solution 2:
val rootObject= JSONObject()
rootObject.put("name","test name")
rootObject.put("age","25")