1

I have an JSONObject which is creating in the following way. For a special reason, I have to convert it to Gson in this way, as i can modify only extractDataToString() method. But I do not get proper value after conversion.

fun createJsonString() {
    val headerJson = JSONObject()
    headerJson.put("typ1", "value1")
    headerJson.put("typ2", "value2")
    extractData(headerJson.toString())
} 

fun extractDataToString(jsonString: String) {
    val headerJson = Gson().fromJson(jsonString, JsonObject::class.java)
    val resultType1 = headerJson.remove("typ1")?.toString() // Here, resultType1 becomes 
                                                                "value1", but it should be 
                                                                 value1 that is extra qutomation 
                                                                 mark is being added.
}

Why extra quotation mark is being added? Can anyone please help? I am a newbie.

1 Answer 1

2

Call

.getAsString()

Instead of

toString()

at the end ref : docs

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.