【发布时间】:2012-03-13 15:44:18
【问题描述】:
假设我有一个 JSON 字符串,例如:
{"title":"aaa","url":"bbb","image":{"url":"ccc","width":"100","height":"200"}, ...
我的访问者:
import com.google.gson.annotations.SerializedName;
public class accessorClass {
@SerializedName("title")
private String title;
@SerializedName("url")
private String url;
@SerializedName("image")
private String image;
// how do I place the sub-arrays for the image here?
...
public final String get_title() {
return this.title;
}
public final String get_url() {
return this.url;
}
public final String get_image() {
return this.image;
}
...
}
还有我的主要:
Gson gson = new Gson();
JsonParser parser = new JsonParser();
JsonArray Jarray = parser.parse(jstring).getAsJsonArray();
ArrayList<accessorClass > aens = new ArrayList<accessorClass >();
for(JsonElement obj : Jarray )
{
accessorClass ens = gson.fromJson( obj , accessorClass .class);
aens.add(ens);
}
您认为在此处获取图像的这些子数组的最佳方法是什么?
【问题讨论】: