Android JSON解析相同属性

Android JSON解析相同属性,android,json,jsonobject,Android,Json,Jsonobject,我有一个JSON响应,如下所示: images: [ { small: "/productimages/247DRFS100374LAV/small/247DRFS100374LAV_1.jpg", medium: "/productimages/247DRFS100374LAV/medium/247DRFS100374LAV_1.jpg", large: "/productimages/247DRFS100374LAV/large/247DRFS100374LAV_1.jpg" }

我有一个JSON响应,如下所示:

 images: [

{

small: "/productimages/247DRFS100374LAV/small/247DRFS100374LAV_1.jpg",

medium: "/productimages/247DRFS100374LAV/medium/247DRFS100374LAV_1.jpg",

large: "/productimages/247DRFS100374LAV/large/247DRFS100374LAV_1.jpg"

},

{

small: "/productimages/247DRFS100374LAV/small/247DRFS100374LAV_2.jpg",

medium: "/productimages/247DRFS100374LAV/medium/247DRFS100374LAV_2.jpg",

large: "/productimages/247DRFS100374LAV/large/247DRFS100374LAV_2.jpg"

}

],
因为图像属性给出了两个属性完全相同的对象(小、中、大),所以我只想从这两个对象中提取大图像。我如何才能做到这一点?

使用。定义表示图像的类,例如:

public class AppImage {
    @SerializedName("small")
    public string SmallImageUrl;

    @SerializedName("medium")
    public string MediumImageUrl;

    @SerializedName("large")
    public string LargeImageUrl;
}
然后将其反序列化为如下所示的数组:

Gson gson = new Gson();
Type imageListType = new TypeToken<List<AppImage>>() {}.getType();
List<AppImage> images = gson.fromJson(json, imageListType);
Gson-Gson=new-Gson();
类型imageListType=newTypeToken(){}.getType();
List images=gson.fromJson(json,imageListType);

经过研究和应用算法,我找到了一个更简单的问题解决方案

JSONArray imgArray = response.getJSONArray("images");

    for (int i = 0; i < imgArray.length(); i++) {
    JSONObject displayPicObject = imgArray.getJSONObject(i);
    String detailPicture = displayPicObject.getString("large");
    }
JSONArray imgArray=response.getJSONArray(“图像”);
对于(int i=0;i
现在,对于每一次迭代,我将得到下一个大图像。我非常感谢你努力回答我的问题。非常感谢。:)