2014-10-01 26 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");