1
我正在與Json合作。我的JSON看起來是這樣的結構爲什麼我在分析我的json響應時看到最後一項?
我使用的AsyncTask解析的json,並顯示在列表視圖中我有一個問題信息jsonarray。我也解析了時間jsonobject,但在arraylist中只添加了最後一個對象。這是我的源代碼
private class CustomerStatistic extends AsyncTask<String, Void, String> {
ProgressDialog pDialog;
@Override
protected void onPreExecute() {
super.onPreExecute();
pDialog = new ProgressDialog(getActivity());
pDialog.setCancelable(false);
pDialog.show();
pDialog.setContentView(R.layout.custom_progressdialog);
}
@Override
protected String doInBackground(String... params) {
return Utils.getJSONString(params[0]);
}
@Override
protected void onPostExecute(String result) {
super.onPostExecute(result);
try {
JSONArray mainJson = new JSONArray(result);
for (int i = 0; i < mainJson.length(); i++) {
JSONObject objJson = mainJson.getJSONObject(i);
objItem = new ServerItems();
objItem.setImage(imageurl + objJson.getString("ipone_4"));
objItem.setTitle(objJson.getString("title"));
objItem.setYoutube(objJson.getString("youtube"));
objItem.setWritten(objJson.getString("written"));
objItem.setCategory(objJson.getString("category"));
objItem.setDescraption(objJson.getString("descraption"));
objItem.setGeorgia_time(objJson.getString("georgia_time"));
objItem.setWold_time(objJson.getString("wold_time"));
objItem.setStars(objJson.getString("stars"));
objItem.setBlurimage(imageurl
+ objJson.getString("ipone_4_blur"));
JSONObject cinema = objJson.getJSONObject("Cinemas");
JSONArray cinemasarray = cinema.getJSONArray("Cinemaname");
for (int j = 0; j < cinemasarray.length(); j++) {
JSONObject objJson1 = cinemasarray.getJSONObject(j);
JSONArray info = objJson1.getJSONArray("info");
for (int k = 0; k < info.length(); k++) {
JSONObject information = info.getJSONObject(k);
objItem.setTime(information.getString("time"));
Log.e("time is", objItem.getTime());
}
}
arrayOfList.add(objItem);
}
} catch (JSONException e) {
e.printStackTrace();
}
if (pDialog != null) {
pDialog.dismiss();
pDialog = null;
}
setAdapterToListview();
}
}
而且還在listview的點擊我更換了新的片段,我也推測我的位置的元素。我有一個問題,只有「時間」 jsobobject 這是我的列表視圖的onclick Java代碼
main_listview.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
mPosition = position;
MoviewListResult newFragment = new MoviewListResult();
FragmentTransaction transaction = getFragmentManager()
.beginTransaction();
Bundle bundle = new Bundle();
bundle.putString("image", arrayOfList.get(position)
.getBlurimage());
bundle.putString("title", arrayOfList.get(position).getTitle());
bundle.putString("trailer", arrayOfList.get(position)
.getYoutube());
bundle.putString("category", arrayOfList.get(position)
.getCategory());
bundle.putString("writer", arrayOfList.get(position)
.getWritten());
bundle.putString("stars", arrayOfList.get(position).getStars());
bundle.putString("geotime", arrayOfList.get(position)
.getGeorgia_time());
bundle.putString("worldtime", arrayOfList.get(position)
.getWold_time());
bundle.putString("descraption", arrayOfList.get(position)
.getDescraption());
bundle.putString("time", arrayOfList.get(position).getTime());
newFragment.setArguments(bundle);
transaction.replace(R.id.content_frame, newFragment);
transaction.commit();
}
});
我到底做錯了什麼?如果有人知道的解決方案,請幫助我 詩 我是新用戶,我不能發佈圖片和請看我Url.i上傳我的形象
謝謝,但我有JsonParse類(Utils).meybe你不瞭解我。我解析了json,但我只有一個問題信息的數組的時間object.please看到我的形象 – lukaaa 2014-10-02 21:00:51