r1299597
r1299597

Reputation: 629

Retrofit parsing json array without key

NOT DUPLICATE, I TRY DID LIKE IN THAT POST, NOT WORK

Sorry for my English. I use retrofit in my android application, and I have some problem with JSON, I try parsing JSON like this:

[
 {
  "FIELDS": {
     "ID": "21"
   },
   "PROS": []
 },
{
  "FIELDS": {
     "ID": "21"
   },
   "PROS": []
 }
]

this is my object:

public class In_Catalog {

    @SerializedName("FIELDS")
    FIELDS FIELDS;

    public In_Catalog.FIELDS getFIELDS() {
        return FIELDS;
    }

    public void setFIELDS(In_Catalog.FIELDS FIELDS) {
        this.FIELDS = FIELDS;
    }

public class FIELDS {
String ID;
 public String getID() {
            return ID;
        }

        public void setID(String ID) {
            this.ID = ID;
        }
}

This is my interface

Observable<List<In_Catalog>> getProductsInCatalog(@Query("section") int id_selection);

I cant parse JSON, my FIELDS object is always NULL. What I do wrong?

Upvotes: 0

Views: 1442

Answers (1)

Nirav Joshi
Nirav Joshi

Reputation: 1723

public class ResultDTO {

@SerializedName("FIELDS")
private com.universal.jainconnection.data.FIELDS mFIELDS;
@SerializedName("PROS")
private List<Object> mPROS;
}


public class FIELDS {

@SerializedName("ID")
private String mID;
}

replace this

Observable<List<ResultDTO >> getProductsInCatalog(@Query("section") int id_selection);

Upvotes: 2

Related Questions