【发布时间】:2018-07-29 16:44:25
【问题描述】:
嘿,伙计,我有一个应用程序正在执行,它可以加载 Android 电视视图的电影。
我有一个站点,其中包含用于登录和内容的数据库中的所有信息。
所以在leanback中,类别已经定义为:
public static final String MOVIE_CATEGORY[] = {
"Category Zero",
"Category One",
"Category Two",
"Category Three",
"Category Four",
"Category Five",
};
但我想从我的数据库中获取信息。
所以我主要创建了 AsyncHttpTask 任务并解析我的响应,我的目标是在我的共享首选项中插入类别并从 MOVIE_CATEGORY 中检索它。
我只需要id和名字
private void parseResult(String result) {
try {
JSONArray jsonarray = new JSONArray(result);
SharedPreferences.Editor editor = getSharedPreferences(MY_PREFS_NAME, MODE_PRIVATE).edit();
for(int i=0; i < jsonarray.length(); i++) {
JSONObject jsonobject = jsonarray.getJSONObject(i);
String id = jsonobject.getString("CID");
String name = jsonobject.getString("name");
//Log.e("TAG","This is the results" + " ID "+ id + " Name "+name);
iD = new String[]{id};
catName=new String[]{name};
editor.putString("id" + i, iD[i] + "name"+ catName[i] );
editor.apply();
Log.e("TAG","This is the results" + Arrays.deepToString(iD));
}
} catch (JSONException e) {
e.printStackTrace();
}
}
但我明白了
键:id0 值:6name2018
我的 json 响应如下所示:
[{"CID":6,"name":"2018","image":"https:\/\/i.ytimg.com\/vi\/zTF913m8jVc\/maxresdefault.jpg"},
{"CID":7,"name":"2017","image":"http:\/\/mtltimes.ca\/wp-content\/uploads\/2017\/12\/Best-movies-2017-493x300.jpg"}
【问题讨论】: