Retrofit-2.0 - pars response with json inside xml

I am using Retrofit 2.0 and I want to parse a custom answer. The POST request contains the json format. while the answer is a combination of both xml and json. request example:

{"loginid":"10051"}

sample response:

<string xmlns="http://www.example.com/">{"user":"user1", "class":"1"}</string>

So, I want to get the json part {"user":"user1", "class":"1"}from the answer.

I tried to write my own converter. But since I'm new to Retrofit 2.0, I can’t write.

Thanks in advance

+4
source share
1 answer

JsonElement, JsonObject JsonArray, . .toString , .

RequestBody :

@POST("/exampleRout")
    Call<JsonElement> foo(@Body RequestBody requestBody);

:

 public void onResponse(Call<JsonElement> call, Response<JsonElement> response) {
       JsonElement jsonElement = response.body();
       String yourResponseString = jsonElement.toString();
       //parse it with regEx or XML parser and etc
}
0

Source: https://habr.com/ru/post/1629059/


All Articles