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:

JsonArrayjArray= 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:

publicclassFooDeserializerimplementsJsonDeserializer<Foos>
{
    @Overridepublic Foos deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)throws JsonParseException
    {
        JsonObjectjsonObject= json.getAsJsonObject();
        JsonArraystatusArray= jsonObject.get("statuses").getAsJsonArray();
        Foosresult=newFoos();
        ArrayListfooArray=newArrayList<>;
        for (JsonElement e : statusArray) {
            fooArray.add(newFoo());
        }
        result.setFoos(fooArray);
        return result;
    }
}

Post a Comment for "Storing Json Object Using Volley"