2016-06-30 7 views
2

Ich bin nicht so neu in Android, aber begann mit der Nachrüstung heute, konnte ich alle Fehler löschen, jetzt gibt der Antwortkörper null zurück. Ich weiß, dass es etwas damit zu tun hat, wie meine Klasse aufgebaut ist. Ich habe keine Ahnung, wie man mit Arrays mit Arrays umgeht. Jede Hilfe wäre willkommen. DankWie behandelt man ein JSON-Array-Objekt mit Retrofit?

[JSON return[1]

Meine Schnittstelle

@GET("/web-api.php?route=feed/web_api/products") 
Call<Product> loadProducts(@Query("category") Integer id, @Query("key")   String apiKey); 

Klasse

public class Product implements Serializable { 
@SerializedName("id") 
private long mId; 
@SerializedName("name") 
private String mname; 
@SerializedName("description") 
private String mText; 
@SerializedName("price") 
private Double mprice; 
@SerializedName("href") 
private String mproductURL; 
@SerializedName("thumb") 
private String mImageURL; 

public Product(long mId, String mname, String mText, Double mprice, String mproductURL, String mImageURL) { 
    this.mId = mId; 
    this.mname = mname; 
    this.mText = mText; 
    this.mprice = mprice; 
    this.mproductURL = mproductURL; 
    this.mImageURL = mImageURL; 
} 

public long getmId() { 
    return mId; 
} 

public void setmId(long mId) { 
    this.mId = mId; 
} 

public String getMname() { 
    return mname; 
} 

public void setMname(String mname) { 
    this.mname = mname; 
} 

public String getmText() { 
    return mText; 
} 

public void setmText(String mText) { 
    this.mText = mText; 
} 

public Double getMprice() { 
    return mprice; 
} 

public void setMprice(Double mprice) { 
    this.mprice = mprice; 
} 

public String getMproductURL() { 
    return mproductURL; 
} 

public void setMproductURL(String mproductURL) { 
    this.mproductURL = mproductURL; 
} 

public String getmImageURL() { 
    return mImageURL; 
} 

public void setmImageURL(String mImageURL) { 
    this.mImageURL = mImageURL; 
} 


@Override 
public String toString() { 
    return mText; 
} 

}

+0

Ihre Retrofit-Klasse nicht mit der Antwort zu helfen. Sie benötigen ein Objekt mit einem booleschen Wert und eine Arraylist der Produkte –

Antwort

1

einfach eine Super-Klasse definieren -

public class ResponseDS{ 
    public boolean success; 
    public Product[] products; 
} 

Und Verwendung ResponseDS statt Produktklasse -

@GET("/web-api.php?route=feed/web_api/products") 
Call<ResponseDS> loadProducts(@Query("category") Integer id, @Query("key")   String apiKey); 

Hope it :)

+0

Es funktioniert so viel – Youngdev