My JSON is:
[
{
"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"
}
]
I am using google gson library. The code I have is:
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();
}
The ExitPropsBean.java is:
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;
}
}
The exception that I get is (Expected BRGIN_OBJECT but was STRING at line 1 column 104):
http://prntscr.com/76mzyg
Could some one help please.
In the ExitPropsBean
, you have this property:
private Bitmap image;
Gson is trying to put a java.lang.String
into it. Either change the type from Bitmap
to String
, or provide a custom deserializer for this type.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With