GSON: Expected a string but was BEGIN_OBJECT?

前端 未结 3 455
迷失自我
迷失自我 2020-12-17 10:02

I\'m trying to use GSON to parse some very simple JSON. Here\'s my code:

    Gson gson = new Gson();

    InputStreamReader reader = new InputStreamReader(ge         


        
3条回答
  •  清酒与你
    2020-12-17 10:48

    This is normal parsing exception occurred when Pojo key data type is different from json response

    This is due to data type mismatch in Pojo class and actually data which comes in the Network api Response

    Eg

    data class ProcessResponse(
            val outputParameters: String,
            val pId: Int 
        )
    

    got the same error due to api gives response as

     {
            "pId": 1",
            "outputParameters": {
              "": ""
            }
        }
    

    Here POJO is outputParameters is String but as per api response its json

提交回复
热议问题