Deserializing json from retrofit using jackson where same variable name can represent two different objects

后端 未结 4 1591
有刺的猬
有刺的猬 2021-01-21 09:46

The response from retrofit2 may be of the following types.(and we don\'t know before hand which response will come)

{
    \"id\": \"abc\",
    \"place\": \"LA\",         


        
4条回答
  •  既然无缘
    2021-01-21 10:14

    Try this

    JSONObject jsonObject = new JSONObject("your Response String");
    Object obj = jsonObject.get("driverId");    //handle Exceptions
    if (obj instanceof String){ 
       //do String stuff
    }
    else if (obj instanceof JSONObject) {
       //do json object stuff
    }
    

提交回复
热议问题