- ich meine jsonArray zu konvertieren Ich versuche habe ich erfolgreich Lage die Daten zu erhalten, aber, wie man Schleife meine jsonArray, so kann ich komplette Detail erhalten in Listenansicht. Und wie kann ich meine Daten anhängen, wenn es mehrere Daten im selben Objekt gibt und parse es in ListView.
Ich habe meine JSONObject in JsonarrayIch habe meine JSONObject in JsonArray Converted Wie kann ich Schleife es
public class getData extends AsyncTask<String, String, String> { @Override protected String doInBackground(String... params) { return JsonParser.makeHttpUrlConnectionRequest(url, getParam()); } private List<NameValuePair> getParam() { SharedPreferences preferences = ReportActivity.this.getSharedPreferences(getString(R.string.detail), MODE_PRIVATE); enroll_no = preferences.getString(getString(R.string.loginenroll), ""); List<NameValuePair> list = new ArrayList<>(); list.add(new BasicNameValuePair("enroll_no", enroll_no)); // Log.e("List", String.valueOf(list.add(new BasicNameValuePair("enroll_no",enroll)))); Log.e("Request in Profile", String.valueOf(list)); return list; } @Override protected void onPostExecute(String httpresponse) { super.onPostExecute(httpresponse); if (httpresponse == null) { Toast.makeText(ReportActivity.this, "Unable to Connect", Toast.LENGTH_SHORT).show(); } else if (httpresponse.equals("error")) { Toast.makeText(ReportActivity.this, "Internal Server Error", Toast.LENGTH_SHORT).show(); } else { try { responseParameter = new JSONObject(httpresponse); JSONObject fees_history = responseParameter.getJSONObject("fees_history"); // JSONObject RC1 = fees_history.getJSONObject("RC1"); Iterator rc1 = fees_history.keys(); JSONArray jsonArray = new JSONArray(); int i = 0; while (rc1.hasNext()) { String key = (String) rc1.next(); jsonArray.put(fees_history.get(key)); JSONObject object = jsonArray.getJSONObject(i++); JSONObject heading = object.getJSONObject("heading"); JSONArray details = object.getJSONArray("details"); Log.e("details", details.toString()); String Amount = heading.getString("Amount"); String date = heading.getString("date"); String Reciept = heading.getString("Reciept"); // for (int j = 0; j < details.length(); j++) { JSONObject detail = details.getJSONObject(i); String Month = detail.getString("Month"); String Amountt = detail.getString("Amount"); Log.e("Amount", Amountt); Log.e("Month", Month); Unpaid_fees_detail unpaid_fees_detail = new Unpaid_fees_detail(Reciept, date, Amount,Amountt,Month); unpaid_fees_details.add(unpaid_fees_detail); } } catch (JSONException e) { e.printStackTrace(); } // Log.e("RC1",RC1.toString()); // Log.e("fees_history", fees_history.toString()); } Unpaid_fees_detail_adapter unpaid_fees_detail_adapter = new Unpaid_fees_detail_adapter(ReportActivity.this, unpaid_fees_details); listView.setAdapter(unpaid_fees_detail_adapter); } }
umgewandelt Und hier ist mein JsonArray
[ { "heading":{ "Amount":11800, "Reciept":"RC1", "date":"29-07-2017" }, "details":[ { "unique_id":"75", "Reciept":"RC1", "Gr_num":"1355", "Amount":"100", "bal":"0", "Month":"Aug", "year":"2017", "fee_type":"Bus Fee", "pay_mode":"cash", "cheque_num":"0", "lflag":"yes", "late_fee":"0", "discount":"0", "reason":"", "date":"2017-06-30", "bank_name":"", "cheque_date":"0000-00-00", "is_cheq_msg_send":"0", "is_active":"1", "cheq_msg":"", "created_at":"2017-06-30 14:08:30", "updated_at":"2017-06-30 14:08:30" }, { "unique_id":"65", "Reciept":"RC1", "Gr_num":"1355", "Amount":"1000", "bal":"0", "Month":"Aug", "year":"2017", "fee_type":"Monthly Fee", "pay_mode":"cash", "cheque_num":"0", "lflag":"no", "late_fee":"0", "discount":"0", "reason":"", "date":"2017-07-29", "bank_name":"", "cheque_date":"0000-00-00", "is_cheq_msg_send":"0", "is_active":"1", "cheq_msg":"", "created_at":"2017-07-29 12:20:52", "updated_at":"2017-07-29 12:20:52" }, { "unique_id":"65", "Reciept":"RC1", "Gr_num":"1355", "Amount":"100", "bal":"0", "Month":"Dec", "year":"2017", "fee_type":"Bus Fee", "pay_mode":"cash", "cheque_num":"0", "lflag":"no", "late_fee":"0", "discount":"0", "reason":"", "date":"2017-07-29", "bank_name":"", "cheque_date":"0000-00-00", "is_cheq_msg_send":"0", "is_active":"1", "cheq_msg":"", "created_at":"2017-07-29 12:20:52", "updated_at":"2017-07-29 12:20:52" }, { "unique_id":"65", "Reciept":"RC1", "Gr_num":"1355", "Amount":"1000", "bal":"0", "Month":"Dec", "year":"2017", "fee_type":"Monthly Fee", "pay_mode":"cash", "cheque_num":"0", "lflag":"no", "late_fee":"0", "discount":"0", "reason":"", "date":"2017-07-29", "bank_name":"", "cheque_date":"0000-00-00", "is_cheq_msg_send":"0", "is_active":"1", "cheq_msg":"", "created_at":"2017-07-29 12:21:12", "updated_at":"2017-07-29 12:21:12" }, { "unique_id":"65", "Reciept":"RC1", "Gr_num":"1355", "Amount":"100", "bal":"0", "Month":"Feb", "year":"2017", "fee_type":"Bus Fee", "pay_mode":"cash", "cheque_num":"0", "lflag":"no", "late_fee":"0", "discount":"0", "reason":"", "date":"2017-07-29", "bank_name":"", "cheque_date":"0000-00-00", "is_cheq_msg_send":"0", "is_active":"1", "cheq_msg":"", "created_at":"2017-07-29 12:21:12", "updated_at":"2017-07-29 12:21:12" }, { "unique_id":"75", "Reciept":"RC1", "Gr_num":"1355", "Amount":"1000", "bal":"0", "Month":"Term 1", "year":"2017", "fee_type":"Monthly Fee", "pay_mode":"cash", "cheque_num":"0", "lflag":"no", "late_fee":"0", "discount":"0", "reason":"", "date":"2017-06-30", "bank_name":"", "cheque_date":"0000-00-00", "is_cheq_msg_send":"0", "is_active":"1", "cheq_msg":"", "created_at":"2017-06-30 14:08:30", "updated_at":"2017-06-30 14:08:30" }, { "unique_id":"75", "Reciept":"RC1", "Gr_num":"1355", "Amount":"7000", "bal":"3000", "Month":"Admission Fee", "year":"2017", "fee_type":"One time", "pay_mode":"cash", "cheque_num":"0", "lflag":"no", "late_fee":"0", "discount":"0", "reason":"", "date":"2017-06-30", "bank_name":"", "cheque_date":"0000-00-00", "is_cheq_msg_send":"0", "is_active":"1", "cheq_msg":"", "created_at":"2017-06-30 14:08:30", "updated_at":"2017-06-30 14:08:30" }, { "unique_id":"65", "Reciept":"RC1", "Gr_num":"1355", "Amount":"1500", "bal":"1500", "Month":"Admission Fee", "year":"2017", "fee_type":"One time", "pay_mode":"cash", "cheque_num":"0", "lflag":"no", "late_fee":"0", "discount":"0", "reason":"", "date":"2017-07-29", "bank_name":"", "cheque_date":"0000-00-00", "is_cheq_msg_send":"0", "is_active":"1", "cheq_msg":"", "created_at":"2017-07-29 12:20:52", "updated_at":"2017-07-29 12:20:52" } ] }, { "heading":{ "Amount":200, "Reciept":"RC2", "date":"30-06-2017" }, "details":[ { "unique_id":"65", "Reciept":"RC2", "Gr_num":"1355", "Amount":"100", "bal":"0", "Month":"Jan", "year":"2017", "fee_type":"Bus Fee", "pay_mode":"cash", "cheque_num":"0", "lflag":"no", "late_fee":"0", "discount":"0", "reason":"", "date":"2017-07-29", "bank_name":"", "cheque_date":"0000-00-00", "is_cheq_msg_send":"0", "is_active":"1", "cheq_msg":"", "created_at":"2017-07-29 12:20:52", "updated_at":"2017-07-29 12:20:52" }, { "unique_id":"75", "Reciept":"RC2", "Gr_num":"1355", "Amount":"100", "bal":"0", "Month":"Jul", "year":"2017", "fee_type":"Bus Fee", "pay_mode":"cash", "cheque_num":"0", "lflag":"yes", "late_fee":"0", "discount":"0", "reason":"", "date":"2017-06-30", "bank_name":"", "cheque_date":"0000-00-00", "is_cheq_msg_send":"0", "is_active":"1", "cheq_msg":"", "created_at":"2017-06-30 14:08:30", "updated_at":"2017-06-30 14:08:30" } ] }, { "heading":{ "Amount":1100, "Reciept":"RC3", "date":"30-06-2017" }, "details":[ { "unique_id":"75", "Reciept":"RC3", "Gr_num":"1355", "Amount":"1000", "bal":"0", "Month":"Jul", "year":"2017", "fee_type":"Monthly Fee", "pay_mode":"cash", "cheque_num":"0", "lflag":"no", "late_fee":"0", "discount":"0", "reason":"", "date":"2017-06-30", "bank_name":"", "cheque_date":"0000-00-00", "is_cheq_msg_send":"0", "is_active":"1", "cheq_msg":"", "created_at":"2017-06-30 14:08:30", "updated_at":"2017-06-30 14:08:30" }, { "unique_id":"75", "Reciept":"RC3", "Gr_num":"1355", "Amount":"100", "bal":"0", "Month":"Jun", "year":"2017", "fee_type":"Bus Fee", "pay_mode":"cash", "cheque_num":"0", "lflag":"yes", "late_fee":"0", "discount":"0", "reason":"", "date":"2017-06-30", "bank_name":"", "cheque_date":"0000-00-00", "is_cheq_msg_send":"0", "is_active":"1", "cheq_msg":"", "created_at":"2017-06-30 14:08:30", "updated_at":"2017-06-30 14:08:30" } ] }, { "heading":{ "Amount":2100, "Reciept":"RC4", "date":"29-07-2017" }, "details":[ { "unique_id":"65", "Reciept":"RC4", "Gr_num":"1355", "Amount":"1000", "bal":"0", "Month":"Jun", "year":"2017", "fee_type":"Monthly Fee", "pay_mode":"cash", "cheque_num":"0", "lflag":"no", "late_fee":"0", "discount":"0", "reason":"", "date":"2017-07-29", "bank_name":"", "cheque_date":"0000-00-00", "is_cheq_msg_send":"0", "is_active":"1", "cheq_msg":"", "created_at":"2017-07-29 12:20:52", "updated_at":"2017-07-29 12:20:52" }, { "unique_id":"65", "Reciept":"RC4", "Gr_num":"1355", "Amount":"100", "bal":"0", "Month":"Nov", "year":"2017", "fee_type":"Bus Fee", "pay_mode":"cash", "cheque_num":"0", "lflag":"no", "late_fee":"0", "discount":"0", "reason":"", "date":"2017-07-29", "bank_name":"", "cheque_date":"0000-00-00", "is_cheq_msg_send":"0", "is_active":"1", "cheq_msg":"", "created_at":"2017-07-29 12:20:52", "updated_at":"2017-07-29 12:20:52" }, { "unique_id":"65", "Reciept":"RC4", "Gr_num":"1355", "Amount":"1000", "bal":"0", "Month":"Nov", "year":"2017", "fee_type":"Monthly Fee", "pay_mode":"cash", "cheque_num":"0", "lflag":"no", "late_fee":"0", "discount":"0", "reason":"", "date":"2017-07-29", "bank_name":"", "cheque_date":"0000-00-00", "is_cheq_msg_send":"0", "is_active":"1", "cheq_msg":"", "created_at":"2017-07-29 12:21:12", "updated_at":"2017-07-29 12:21:12" } ] } ]
0
A
Antwort
1
Sie gerade fori
Schleife
ArrayList<DetailItem> detailItems = new ArrayList<>();
JSONArray details = response.getJSONArray("details");
if (details != null) {
for (int k = 0; k < details.length(); k++) {
JSONObject jsonObject = details.getJSONObject(k);
String uniqueId = jsonObject.getString("unique_id");
String reciept = jsonObject.getString("Reciept");
// Your Code ...
DetailItem detailItem = new DetailIte();
detailItem.setUniqueId(uniqueId);
detailItem.setReciept(reciept);
// Your Code ...
detailItems.add(detailItem);
// Your Code ...
}
}
Sie Erstellt zu machen: JSONArray details = Objekt.getJSONArray ("Details");
So verstehe ich nicht über: JSONObject detail = details.getJSONObject (i);
Ändern Sie Ihren Code von dieser Zeile: JSONArray details = object.getJSONArray ("Details");
Like:
JSONArray details = response.getJSONArray("details");
// List Of Custom Object Class 'DetailItem'
// It Contains fields of details object , unique_id and Reciept and etc
ArrayList<DetailItem> detailItems = new ArrayList<>();
if (details != null) {
for (int k = 0; k < details.length(); k++) {
JSONObject jsonObject = details.getJSONObject(k);
String uniqueId = jsonObject.getString("unique_id");
String reciept = jsonObject.getString("Reciept");
// Your Code ...
DetailItem detailItem = new DetailIte();
detailItem.setUniqueId(uniqueId);
detailItem.setReciept(reciept);
// Your Code ...
detailItems.add(detailItem);
// Your Code ...
}
}
Verwandte Themen
- 1. Wie Schleife durch JSONArray innerhalb JSONObject
- 2. JsonObject JsonArray Parsing Problem
- 3. Java JsonObject von JsonArray
- 4. Testen Sie, ob es JSONObject oder JSONArray
- 5. Verarbeitung JSONArray, JSONObject
- 6. Wie man in JSONObject das korrekte JsonArray mit JSONObject erstellt
- 7. JsonArray und JsonObject
- 8. JSONObject vs JSONArray Swift
- 9. JSONObject-Daten in JSONArray duplizieren
- 10. Fehler beim Konvertieren von JSONArray in JSONObject
- 11. JSONArray & JSONObject Fehler
- 12. erstellen JSONArray von JSONObject
- 13. JSONObject kann nicht in JSONArray umgewandelt werden, wenn json anfordernden
- 14. Android: JSONArray kann nicht in JSONObject konvertiert werden
- 15. Java, setzen JsonObject in JsonArray, aber JsonArray nehmen den gleichen Wert am Ende der for-Schleife
- 16. Wie kann auf JSONObject, in JSONObject, in einem JSONArray zugegriffen werden? Java/Android
- 17. JSONObject zu JSONArray hinzufügen java
- 18. Unterschied zwischen JSONObject und JSONArray
- 19. Wie kann ich meine Regex-Schleife umschreiben?
- 20. Erste Daten aus JSONObject in JSONArray von JSONObject
- 21. Converting JSONArray innerhalb JSONObject in einzelne JSONObjects
- 22. Wie kann ich meine App beschleunigen?
- 23. JsonObject können nicht konvertiert zu jsonArray
- 24. wie kann ich ein Android JSONArray witin einem JSONObject durchqueren haben
- 25. Wie schleife ich meine Audiodatei?
- 26. JSONArray und JSONObject für Google Kalender
- 27. JSON Parsing Converted Fehler
- 28. Wie bekomme ich bestimmte Daten von jsonarray?
- 29. Wann wählen Sie JSONObject vs JSONArray
- 30. Fügen Sie JsonArray zu JsonObject hinzu
Ich würde Blick in Gson Bibliothek vorschlagen und –