新手在安卓這裏,用JSON數組是這樣的:結合的Json數組值的ListView的Android
[{"SITE_NAME":"JAKARTA","GROUP_LABEL":"FINANCE","COMPANY_ID":"DDT","COMPANY_NAME":"PT. DIADYANI TIMBER","LABEL":"Expenses Req. (EXP)/Pembayaran","TOTAL":1,"SITE_ID":"JKT"},
{"SITE_NAME":"JAKARTA","GROUP_LABEL":"FINANCE","COMPANY_ID":"SPT","COMPANY_NAME":"PT. SARMIENTO PARAKANTJA TIMBER","LABEL":"Expenses Req. (EXP)/Pembayaran","TOTAL":3,"SITE_ID":"JKT"},
{"SITE_NAME":"JAKARTA","GROUP_LABEL":"FINANCE","COMPANY_ID":"TBP","COMPANY_NAME":"PT. TELAGA BAKTI PERSADA","LABEL":"Expenses Req. (EXP)/Pembayaran","TOTAL":1,"SITE_ID":"JKT"},
{"SITE_NAME":"JAKARTA","GROUP_LABEL":"FINANCE","COMPANY_ID":"SPT","COMPANY_NAME":"PT. SARMIENTO PARAKANTJA TIMBER","LABEL":"Payment Req(AP/PO)/Rencana Pembayaran","TOTAL":1,"SITE_ID":"JKT"}]
我分析他們在我的佈局,ListView控件是這樣的:
- 圖像鏈接:1
見行號2和4, 有相同的名稱COMPANY_NAME
具有不同LABEL
我要問什麼,我能加入他們,結果會是這樣:
PT.SARMIENTO PARAKANTJA木材
費用所需物品。 (EXP)/ Pembayaran - JKT(3)
付款請求(AP/PO)/ Rencana Pembayaran - JKT(1)
然後會有3行,而不是4 ListView中相同COMPANY_NAME。
我該做什麼?新手需要建議。 更新時間:
這是HomeDataList.class
public class HomeDataList {
public String COMPANY_NAME;
public String TOTAL;
public String SITE_ID;
public String LABEL;
public HomeDataList(String COMPANY_NAME, String LABEL, String SITE_ID, String TOTAL)
{
this.COMPANY_NAME = COMPANY_NAME;
this.TOTAL = TOTAL;
this.LABEL = LABEL;
this.SITE_ID = SITE_ID;
}
}
這是我的解析代碼:
try {
JSONArray jsonArray = new JSONArray(result);
for (int i = 0; i < jsonArray.length(); i++) {
JSONObject mJsonObjectProperty = jsonArray.getJSONObject(i);
String COMPANY_NAME = mJsonObjectProperty.getString("COMPANY_NAME");
String TOTAL = mJsonObjectProperty.getString("TOTAL");
String SITE_ID = mJsonObjectProperty.getString("SITE_ID");
String LABEL = mJsonObjectProperty.getString("LABEL");
listItem.add(new HomeDataList(COMPANY_NAME, LABEL, SITE_ID, TOTAL));
}
homeDataAdapter.notifyDataSetChanged();
} catch (JSONException e) {
Log.e("APP", "exception", e);
}
是的,你可以這樣做,讓你在這裏解析代碼 –
@AbhishekSingh完成了,我在帖子中更新了它 – FaisalTanjungDotCom