Edit Found Solution:
Found the error in my code. I'm running this on a unit test and Android doesn't use JSON objects on unit tests because it's part of android. That's why it was returning null.
Question:
I'm tying to convert my String back to a JsonObject using JSONObject("string")
Here is a sample of my String:
{
"sessions": [
{
"locations": [
{
"lat": "14.2294625",
"lng": "121.1509005",
"time": 1560262643000,
"speed": 0,
"speedLimit": 0
},
{
"lat": "14.2294576",
"lng": "121.1509498",
"time": 1560262713000,
"speed": 0,
"speedLimit": 0
},
{
"lat": "14.2294576",
"lng": "121.1509498",
"time": 1560262714000,
"speed": 0,
"speedLimit": 0
}
],
"name": "1.5645220491E12"
}
]
}
Its returning null on my JsonObjects:
content = "the string above"
var obj = JSONObject(content.substring(content.indexOf("{"), content.lastIndexOf("}") + 1))
System.out.println("obj1: " + obj.toString())
obj = JSONObject(content)
System.out.println("obj1: " + obj.toString())
var obj1 = JSONArray(content)
System.out.println("obj1: " + obj1.toString())
obj1 = JSONArray(content.substring(content.indexOf("{"), content.lastIndexOf("}") + 1))
System.out.println("obj2: " + obj1.toString())
All the outputs of this are null. Any way to know what error happens so I can adjust my json string?