1

I want to retrieve a JSON object from Okhttp3 response. Service sends an image as a byte array with its status in a JSON object.

Server response as follows:

{
    "msg":"success",
    "msg_code":"001",
    "file":"<200 OK OK,URL [file:/E:/storage/bbb.jpg],[Content-Type:\"image/jpeg\"]>"
}

I can retrieve image when the service directly send byte array as the response, using response.body().bytes()

But I couldn't when the service sends image data inside JSON object.

Rohit5k2
  • 17,948
  • 8
  • 45
  • 57
anjanagnet
  • 51
  • 6

1 Answers1

0

I think you may get response.body().bytes() = null on main thread because of output steam is already close.
Can you try the same way on "Background thread" by calling call.execute()

//Sorry i'm not native English speaker

siwarak
  • 177
  • 13
  • I'm calling network request using a background thread and I can get the result when service just sending the byte array as the response. But I can't when service sends the response as a json object. – anjanagnet Aug 13 '19 at 07:33
  • Could you provide some source code while convert JSON object to byte array. – siwarak Aug 14 '19 at 04:05