2017-05-15 14 views
0

私はAndroidのアプリを書いています。このアプリには画像と簡単な説明が表示されています。現在、YouTubeチュートリアルを使って情報を取得しています。jsonの画像データを解析する

何らかの理由でJSONを正しく解析できず、画像と情報を表示できません。

任意の助けをいただければ幸い、ここに私のJSON形式です:

https://gist.githubusercontent.com/fernandopuma/d33dffc07c9dfec267ff2029e79ad125/raw/fff8018e890d34b690bfaeda630249917dd2bc42/galeria.json

そして、この:

https://gist.githubusercontent.com/draskomikic/372a8ca88d6d88ec2e45/raw/e95badd14bf24abc1b7a6dfdf4a8070515650eca

秒1は、現在values/strings.xml内の私のプロジェクトに座っている:

は、
<string name="gallery_feed">https://gist.githubusercontent.com/draskomikic/372a8ca88d6d88ec2e45/raw/e95badd14bf24abc1b7a6dfdf4a8070515650eca</string> 

これはJSON例で動作します:

.../com.tutsplus.zoo E/Zoo: https://raw.githubusercontent.com/PaulTR/GettingStartedWithAndroid/master/images/gallery/thumbnail_grizzly.jpg 

しかし、私は私が

.../com.tutsplus.zoo E/Zoo: Retrofit error 404 Not Found 

を作り、これはJSON

public class GalleryImage { 

private String thumbnail; 
private String image; 
private String caption; 

public GalleryImage() { 

} 

public GalleryImage(String thumbnail, String image, String caption) { 
    this.thumbnail = thumbnail; 
    this.image = image; 
    this.caption = caption; 
} 

public String getThumbnail() { 
    return thumbnail; 
} 

public void setThumbnail(String thumbnail) { 
    this.thumbnail = thumbnail; 
} 

public String getImage() { 
    return image; 
} 

public void setImage(String image) { 
    this.image = image; 
} 

public String getCaption() { 
    return caption; 
} 

public void setCaption(String caption) { 
    this.caption = caption; 
} 
} 

取得するためのコードであるJSONで何を得ますインターフェイスクラス:

public interface GalleryApiInterface { 

@GET("/Gallery") 
void getStreams(Callback<List<GalleryImage>> callback); 
} 

ありがとうございます。

+2

リンクは404を返します..あなたは、あなたのモデルに直接JSONをマッピングするためにGsonを使用することができますし、それを使うのは非常に簡単です。 –

+0

と私はそれを修正する方法は? gist.github.comに何か提案をアップロードしましたか?よくそれはあなたがそれを初期化するときに改造する渡しているURLは何ですか?古いが、私はこの1つを入力して、まだ何も https://gist.githubusercontent.com/fernandopuma/e96b9225d8386c293a2eb029a0c4ec4d/raw/eba2646e82af618c32edc6d41be01d78a42080cd/gallery.json –

+0

ましたか –

答えて

0

最初にそれを修正し、

Gson gson = new Gson(); 
GalleryImage galleryImage = gson.fromJson(yourJsonObject, GalleryImage.class); 
+0

これはインターフェイスクラスで実装する必要がありますか? –

+0

いいえ、モデルをSerializableを実装してから、このライブラリをインポートしてください。 –