1

I have no error message but the parsing simply doesn't seem to work. Here's the compact JSON response :

json response

My "WPPost" has a problem :

    public class WPPost {

    int id;
    String title;
    String content;
    ArrayList<WPPostAttachment> attachments;
    WPPostCustomFields custom_fields;

    public String getContent() {
        return content;
    }

    public String getTitle() {
        return title;
    }

    public int getId() {
        return id;
    }

    public ArrayList<WPPostAttachment> getAttachments() {
        return attachments;
    }

    public WPPostCustomFields getCustomFields() {
        return custom_fields; //Problem here
    }

}

The WPPostAttachement getter works well but its structure is different to the custom field structure.

    public class WPPostAttachment {

    String id;
    String url;
    String title;

    public String getId() {
        return id;
    }

    public String getUrl() {
        return url;
    }

    public String getTitle() {
        return title;
    }

}

    public class WPPostCustomFields {

    String address;

    public String getAddress() {
        return address;
    }

}

How should I change the WPPost class to make the parsing work ?

4
  • instead of image can you provide the text of the above json object? Commented May 5, 2016 at 4:48
  • Just copy and paste your json here pojo.sodhanalibrary.com Commented May 5, 2016 at 4:51
  • Here it is : sharkmapp.com/api/shark/get_bars_by_city/?cat=3 Commented May 5, 2016 at 7:50
  • It's about parsing : "custom_fields": { "address": [ "230 Bach Dang st, Da Nang, Vietnam" ], "ratings_users": [ "1" ], "ratings_score": [ "5" ], "ratings_average": [ "5" ] } Commented May 5, 2016 at 9:08

2 Answers 2

1

You can use this online tool to convert your json object to POJO(Plain Old Java Object) type. Copy paste your json and set Source type: JSON and Annotation style: GSON. Change the package and class name the way you like. Hope this helps. If you are still unable to get the proper POJO, you can give me your json object in text format and i'll convert it to POJO. Thanks.

Sign up to request clarification or add additional context in comments.

2 Comments

Can it convert the JSON that I receive without breaking my parsing ?
You do not need to do any parsing now a days. Just use google's own volley library and make a GSON request call in which you just pass the name of your main model class. Json values will automatically get set in your model's setters.
0
public JsonObject getCustomFields() {
    return custom_fields;
}

1 Comment

Please don't just add some code but also explain what you are doing and why this will help the OP

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.