我的JSON是:
[
{
"name": "Gears Live Wallpaper",
"url": "market://details?id=com.appbasic.gearslivewallpaper",
"image": "http://appbasic.com/promimg/gearslivewallpaper.png"
},
{
"name": "Phone hanging too much ?",
"url": "market://details?id=com.indiaapps.speedmaster",
"image": "http://appbasic.com/promimg/speedmaster1.png"
},
{
"name": "Rainbow Photo Frames",
"url": "market://details?id=com.appbasic.rainbowphotoframes",
"image": "http://appbasic.com/promimg/rainbowphotoframes.png"
},
{
"name": "Military Photo Suit",
"url": "market://details?id=com.appbasic.militaryphotosuit",
"image": "http://appbasic.com/promimg/militaryphotosuit.png"
}
]
我正在使用谷歌gson库。我的代码是:
try {
URL twitter = new URL(
"http://www.javaexperience.com/android/apps.json");
URLConnection tc = twitter.openConnection();
BufferedReader in = new BufferedReader(new InputStreamReader(
tc.getInputStream()));
Gson gson=new Gson();
TypeToken<List<ExitPropsBean>> token = new TypeToken<List<ExitPropsBean>>() {};
MenuActivity.apps = gson.fromJson(in, token.getType());
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
ExitPropsBean.java是:
public final class ExitPropsBean {
private Bitmap image;
private String name;
private String url;
public final String getName() {
return this.name;
}
public final String getUrl() {
return this.url;
}
public final Bitmap getImage() {
return this.image;
}
public final void setName(String var1) {
this.name = var1;
}
public final void setUrl(String var1) {
this.url = var1;
}
public final void setImage(Bitmap var1) {
this.image = var1;
}
}
我得到的例外是(预期BRGIN_OBJECT但在第1行第104列STRING):
请有人帮忙。
答案 0 :(得分:10)
在ExitPropsBean
中,您拥有此属性:
private Bitmap image;
Gson试图将java.lang.String
加入其中。要么将类型从Bitmap
更改为String
,要么为此类型提供custom deserializer。