2014-10-01 43 views
1

我试图用改造库从服务器位得到这样:改造得到位图

@GET("/products/{ean}/image") 
Bitmap getBitmapByEan(@Path("ean") String ean); 

但我recived错误:

Caused by: com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected BEGIN_OBJECT but was STRING at line 1 column 1 

我恐怕无法在此得到位图因为我看到它是字符串类型不是位图,我无法将其转换。我是对的,也许有可能做到?

+0

欢迎来到SO!在发布问题前请阅读http://stackoverflow.com/help/how-to-ask。 – 2014-10-01 11:19:20

回答

0

广场的改造目前支持GSON和XML内容格式类型这样

GSON:

Gson gson = new GsonBuilder() 
    .setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES) 
    .registerTypeAdapter(Date.class, new DateTypeAdapter()) 
    .create(); 

RestAdapter restAdapter = new RestAdapter.Builder() 
    .setEndpoint("https://api.github.com") 
    .setConverter(new GsonConverter(gson)) 
    .build(); 

GitHubService服务= restAdapter.create(GitHubService.class);

XML:

RestAdapter restAdapter = new RestAdapter.Builder() 
    .setEndpoint("https://api.soundcloud.com") 
    .setConverter(new SimpleXMLConverter()) 
    .build(); 

SoundCloudService service = restAdapter.create(SoundCloudService.class); 

您正在处理的文件I/O类型,无论是你需要,你需要建立自己的SimpleBitmapConverter()或者干脆用其他图像载入库像Koush ION

加载的图像成的ImageView /位图与Koush ION:

//这是“长”的方式来做到建立一个ImageView的请求..它允许你设置标题等。

Ion.with(context) 
.load("http://example.com/image.png") 
.withBitmap() 
.placeholder(R.drawable.placeholder_image) 
.error(R.drawable.error_image) 
.animateLoad(spinAnimation) 
.animateIn(fadeInAnimation) 
.intoImageView(imageView); 

// but for brevity, use the ImageView specific builder... 
Ion.with(imageView) 
.placeholder(R.drawable.placeholder_image) 
.error(R.drawable.error_image) 
.animateLoad(spinAnimation) 
.animateIn(fadeInAnimation) 
.load("http://example.com/image.png");