Skip to content Skip to sidebar Skip to footer

Storing JSON Object Using Volley

This is the structure of the JSON I need to Load, { 'readme_0' : 'THIS JSON IS THE RESULT OF YOUR SEARCH QUERY - THERE IS NO WEB PAGE WHICH SHOWS THE RESULT!', 'readme_1' :

Solution 1:

You could define a custom deserializer and register a type adapter with GSON. Also why are you using this:

JsonArray jArray = parser.parse(Tempx.getString("GSON_FEED","")).getAsJsonArray();

.. when you intend to use GSON for deserialization? You could just do it in your deserializer.

https://sites.google.com/site/gson/gson-user-guide#TOC-Custom-Serialization-and-Deserialization

EG:

public class FooDeserializer implements JsonDeserializer<Foos>
{
    @Override public Foos deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException
    {
        JsonObject jsonObject = json.getAsJsonObject();
        JsonArray statusArray = jsonObject.get("statuses").getAsJsonArray();
        Foos result = new Foos();
        ArrayList fooArray = new ArrayList<>;
        for (JsonElement e : statusArray) {
            fooArray.add(new Foo());
        }
        result.setFoos(fooArray);
        return result;
    }
}

Post a Comment for "Storing JSON Object Using Volley"