I am new to Kotlin
and I want to make a simple JSON
Object, I made the same code in Swift
and had no problems.
But now in the JSON
object that I have a list
of Double
s, after printing the JSON I see that the List is surrounded by "
as it is a string value. How can I get rid of those "
s?
Desired:
{
"title": "need help moving",
"description": "moving stuff from apartment",
"points": 10,
"loc" : { "coordinates" : [0,0], "type" : "Point" }
}
I have made the below code for it:
My Code So Far:
val loc = listOf(22.4577654, 22.4577654)
val locationObject = JSONObject()
locationObject.put("coordinates", loc)
locationObject.put("coor", loc as Any)
locationObject.put("type" ,"Point")
val params = JSONObject()
params.put("title", "$taskTitle")
params.put("description", "$taskDescription")
params.put("points", pointsEditText.text)
params.put("loc", locationObject)
But now my JSON looks like this:
Current Output:
{
"title":"This is Android Task",
"description":"This is Android Task I made via the Android App :D",
"points":"5",
"loc":{
"coordinates":"[22.4577654, 22.4577654]",
"coor":"[22.4577654, 22.4577654]",
"type":"Point"
}
}
Would be better if you suggest solutions without needing to install different libraries :)
Thanks