giuseppebrb giuseppebrb - 1 year ago 124
JSON Question

Android- App with Wordpress API e GSON

i'm trying to make an android native app for my Wordpress blog. I heard that Wordpress has JSON-API to handle the information of a blog but I don't know how I could use it. Please, could someone give me a tiny introduction of its use and if I could use the GSON library to manage the information within my Android app?

Answer Source

Simple example to parse/deserialize your JSON string

String jsonStr = "{\"name\": \"A\", \"address\":\"XYZ\"}";

// You can convert your Json string to JsonObject as below

Gson gson = new Gson();
JsonElement element = gson.fromJson (jsonStr, JsonElement.class);
JsonObject jsonObj = element.getAsJsonObject();

// If you can define a POJO class for your Json, you can convert json to java object

public class MyData {
    private String name;
    private String address;
    //Setters and Getters   

Gson gson = new Gson();
MyData data = gson.fromGson(jsonStr, MyData.class);

Refer Gson API documentation for more details. Hope this will be helpful.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download