0

So, I am getting a json from a webservice:

[{"id":1,"Home":{"id":11,"homtype":{"id":4,"name":"2-bedroom"}, "image":[71,73,70,56,57,97,200,0,200,0,247,0,0,0,0,0,0,0,51,0,0,102,0,0,153,0,0,204,0,0,255,0,43,0,0,43,51,0,43,102,0,43,153,0,43,204,0,43,255,0,85,0,0,85,51,0,..]}]

This json is serialized already on the web service side. What I'd like to retrieve is the byte array of the image in my android app but I need to deserialize the json string first in my android. I am able to get the json string but how do I deserialize it?

  • Check this http://stackoverflow.com/questions/15060514/deserializing-a-json-object-with-multiple-items-inside-it – Sunil Sunny Aug 04 '15 at 04:58

1 Answers1

0

You can deserialize JSON object from String with JSONArray or JSONObject class like this:

JSONArray jsonArray = new JSONArray(jsonString);

But if you process huge data objects I recommend you to use stream deserialization libraries, for example Jackson Streaming API

  • Yeah I've tried using the JSONObject before but I couldn't retrieve all of my data. If I use the Jackson, don't I need to serialize it first? I can't deserialize it straight right? – user3283034 Aug 04 '15 at 03:56
  • What kind of data can't you to retrieve with JSONObject? Jackson works with data serialized in JSON string. But you must write your own code to process JSON tokens to objects you want. – Alexander Soloshenko Aug 04 '15 at 04:06
  • I want to get the whole image data like [71,73,70,56,57,97,....,0,59] but I'm only getting a certain length cos when I try to convert it to a byte array I get [B@1a7b0da4, which is not complete. – user3283034 Aug 04 '15 at 04:20