Retrofit2 を使用して JSONObject を取得できますか? Movie.java で何が間違っていますか?
ログキャット
[Movie] title: Star Wars: The Force Awakens, wiki: https://en.wikipedia.org/wiki/Star_Wars:_The_Force_Awakens
rel:
test.json
{
"title":"Star Wars: The Force Awakens",
"wiki":"https://en.wikipedia.org/wiki/Star_Wars:_The_Force_Awakens",
"release_dates": { "theater":"2015.12.17", "online":"2016.2.17", "dvd":"2016.01.17" }
}
ServiceAPI.java
public interface ServiceAPI {
@GET("/txt2lrn/bollywood/test.json")
Observable<Movie> getTestRx();
}
MyApplicationB.java
public class MyApplication extends Application {
private static ServiceAPI mService;
@Override
public void onCreate() {
super.onCreate();
Retrofit retrofit = new Retrofit.Builder()
.baseUrl("http://goanuj.freeshell.org")
.addConverterFactory(GsonConverterFactory.create())
.addCallAdapterFactory(RxJavaCallAdapterFactory.create())
.build();
mService = retrofit.create(ServiceAPI.class);
}
public static ServiceAPI getServiceAPI() {
return mService;
}
}
ムービー.java
public class Movie {
private final String TAG = getClass().getSimpleName();
private String title, wiki;
private JSONObject release_dates;
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getWiki() {
return wiki;
}
public void setWiki(String wiki) {
this.wiki = wiki;
}
public void setRelease_dates(JSONObject j) {
Log.d(TAG, "j: " + j.toString());
this.release_dates = j;
}
public String getRelease_dates() {
String date = "";
try {
date = this.release_dates.getJSONObject("theater").toString();
} catch (JSONException e) {
Log.d(TAG, e.getMessage());
}
return date;
}
@Override
public String toString() {
final StringBuffer sb = new StringBuffer("[Movie] title: ");
sb.append(this.title);
sb.append(", wiki: ").append(this.wiki);
sb.append("\n\trel: ").append(this.getRelease_dates());
return sb.toString();
}
}