giuseppebrb giuseppebrb - 2 months ago 27x
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?


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.