My api prints a simple json object like this:
{"status":1}
How to say that retrofit (v2) pass it to gson and return an JSONObject contains this key-value pair in response?
I tried following:
Call<JSONObject> result();
But when prints response.body()
in onResponse (Response<JSONObject> response)
method, it returns {}
which means it's empty.
Retrofit is a REST Client for Java and Android allowing to retrieve and upload JSON (or other structured data) via a REST based You can configure which converters are used for the data serialization, example GSON for JSON.
After lots of R&D I got answer. Please find it below
Use JsonObject
from package com.google.gson
instead of JSONObject
from package org.json
After that call Call<JsonObject> result()
and in onResponse (Response<JsonObject> response)
method used to call response.body()
or response.body().toString();
it wil print correct Json from apiwhatever you want
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With