how to get body from the response entity
16,820
You can achieve using:
ResponseEntity<String> response= new ResponseEntity<String> ("\"<200 OK OK,{\\\"status\\\":200,\\\"success\\\":true,\\\"info\\\":{\\\"mid\\\":\\\"id\\\":\\\"95706\\\"}}},[]>\"", HttpStatus.OK);
String responseStr = response.getBody();
int begin = responseStr.indexOf("{");
int end = responseStr.lastIndexOf("}") + 1;
responseStr = responseStr.substring(begin, end);
System.out.println(responseStr);
It will print:
{\"status\":200,\"success\":true,\"info\":{\"mid\":{\"id\":\"95706\"}}}
Related videos on Youtube
Author by
vikas
Updated on June 04, 2022Comments
-
vikas almost 2 years
This is my
ResponseEntity<String> response= new ResponseEntity<String> ( "\"<200 OK OK,{\\\"status\\\":200,\\\"success\\\":true,\\\"info\\\":{\\\"mid\\\":{\\\"id\\\":\\\"95706\\\"}}},[]>\"", HttpStatus.OK);
how to extract json from this response?
tried
response.getBody()
but giving me entire string.Any help would be appreciated
response.getBody() but giving me entire string. ResponseEntity<String> response= new ResponseEntity<String> ( "\"<200 OK OK,{\\\"status\\\":200,\\\"success\\\":true,\\\"info\\\":{\\\"mid\\\":{\\\"id\\\":\\\"95706\\\"}}},[]>\"", HttpStatus.OK);
response.getBody(); giving entire string not the json
-
M. Deinum almost 5 yearsThat
String
is the body, so why should it return something else.
-