Search code examples
androidjsonkotlinretrofit

Unexpected Error : Unexpected character encountered while parsing value: }. Path 'resultData.data', line 1, position 184


I don't understand what is problem clearly. When I searched it in google, I don't decide my reponse model is problem or the json response is problem and should change. Which one? I can't find solution for Kotlin. How I should solve this?

response JSON:

"data":{
      "productInfo":{
         "data":{
            "toBarcode":"2704439285463",
            "productJson":{
               "p_no":"28420000",
               "p_name":"ASA"
            }
         }
      },
      "moves":{
         "data":[
            {
               "fisAcik":"MALVERENDEN",
               "toBarcode":"2704439285463",
               "toJson":{
                  "to_Hks_Adi":"DAĞITIM MERKEZİ"
               },
               "movementJson":{
                  "isleme_Tarihi":"21/12/2022 02:19:30"
               }
            }
         ]
      }
   }

Data.kt

data class Data(
        val productInfo: ProductInfo,
        val moves: Moves
    )
    
    data class Moves (
        val data: List<MovesItem>
    )
    
    data class MovesItem (
        @SerializedName("fisAcik")
        val receiptExplanation: String,
        val toBarcode: String,
        val toJson: ToJson,
        val movementJson: MovementJson
    )
    
    data class MovementJson (
        @SerializedName("isleme_Tarihi")
        val processDate: String
    )
    
    data class ToJson (
        @SerializedName("to_Hks_Adi")
        val toUnitHksName: String
    )
    
    data class ProductInfo (
        val data: ProductInfoItems
    )
    
    data class ProductInfoItems (
        val toBarcode: String,
        val productJson: ProductJson
    )
    
    data class ProductJson (
        @SerializedName("p_No")
        val migrosProductNo: String,
        @SerializedName("p_Name")
        val migrosProductName: String
    )

method that using to call request.

suspend fun dataGetInfo(@Body request: DataRequest): NetworkResult<BaseResponse<Data>>

Solution

  • This error was from my wrong request. I saw Ios has same error also when request with wrong value. So, for who will look this quesiton, they should understand it's not from response or kotlin. Check your value it is clearly what request need.