Trying to handle the response from API in Android Studio by using Kotlin. When converting the response of server from string to json the null
values are converted as "null"
. If the value is null
I want it as null
. How to solve this problem?
Volley portion of the code:
val stringRequest = StringRequest(Request.Method.GET, url,
Response.Listener<String> { response ->
jsonList = JSONArray(response) }
Response of the server:
[
{
"id": 213,
"dummy": null
}
]
Call as Json
jsonList.getJSONObject(0).get("dummy")
Result of call:
As a result the below code will return "null"
which is totally useless.
jsonList.getJSONObject(0).get("dummy")?.toSting()
2
Answers
You can use like
if the result value is null it return empty string,
and if you want to get null you should remove .toString()
You can check
It will hold true in your case
So you could do something like this