0

When I start request using retrofit 2.0, I'm getting this error com.google.gson.stream.MalformedJsonException: Use JsonReader.setLenient(true) to accept malformed JSON at line 1 column 1 path $ and don't know why, becoause I have a valid json. I have also seen this kind of error but didn't helped, I don't want to use JsonReader and this kind of stuff

P.S I'm using Gson for converter

[
  {
    "fullname": "name",
    "contact": "blah",
    "uid": "001"
  },
  {
    "fullname": "name2",
    "contact": "blah2",
    "uid": "002"
  }
]

this is my call interface method

@FormUrlEncoded
@POST("url")
fun startRequest(@Field("someField") someField: String) : Call<List<MyModelExample>>

and this is my response MyModelExample class

open class MyModelExample : RealmObject() {
   @SerializedName("fullname")
   var fullName: String? = null

   @SerializedName("contact")
   var contact: String? = null

   @PrimaryKey
   @SerializedName("uid")
   var uid: String = ""
}
Jemo Mgebrishvili
  • 5,187
  • 7
  • 38
  • 63
  • 1
    Possible duplicate of [gson throws MalformedJsonException](https://stackoverflow.com/questions/11484353/gson-throws-malformedjsonexception) – sushildlh Jun 05 '17 at 17:27
  • Nope, I want to parse data using retrofit convertfactory – Jemo Mgebrishvili Jun 05 '17 at 17:34
  • @Jemo, it's not a Retrofit issue. Just configure your Gson according to the linked Q/A, and pass it your `GsonConverterFactory`. However, add a logging interceptor to your `OkHttpClient` or `Retrofit.Builder` instances to spot the real issue with your JSON. – Lyubomyr Shaydariv Jun 05 '17 at 18:31
  • I have a logging interceptor and logged response is same as posted here, also I tried to pass the gson to convertactory and after that problem were "expected jsonarray but was string" – Jemo Mgebrishvili Jun 05 '17 at 18:36
  • @Jemo Well, it's hard to say, but it looks like you have either something wrong with the server response, or you have declared an array elsewhere. Since your example has the top level array, I believe the case #1 (you Retrofit method declaration looks good to me). Make sure that there are no leading/trailing extra characters. – Lyubomyr Shaydariv Jun 06 '17 at 06:30

0 Answers0