我嘗試創建包含多個JsonArray
和JsonObject
的Json字符串。我想創建Json字符串,格式如下所示:創建Json多個數組字符串在android
[
{
"CustomerId": -1,
"PoolGuyId": 117,
"FilterChanges": [
{
"FilterChangeId": -1,
"CustomerId": -1,
"Reminders": [
{
"ReminderId": -1,
"FilterChangeId": -1,
"CustomerId": -1
},
{
"ReminderId": -2,
"FilterChangeId": -1,
"CustomerId": -1
}
]
},
{
"FilterChangeId": -2,
"CustomerId": -1,
"Reminders": [
{
"ReminderId": -3,
"FilterChangeId": -1,
"CustomerId": -1
}
]
}
],
"IsDeleted": false
}
]
我試了很多參考,但仍然沒有創建我的字符串。 幫我
我從數據庫中獲得價值。在sqlite數據庫中有3個名爲customerDetails,JobHistory,Reminder的表。在這些表格中存儲多個值。
try {
customerDetailsTable = new CustomerDetailsTable(con);
customerDetailsTable.open();
arrayListCustomer = customerDetailsTable.getAllContacts();
customerDetailsTable.close();
JSONObject objCust = null;
JSONArray jsonArrayCust = new JSONArray();
for (int i = 0; i < arrayListCustomer.size(); i++) {
customerDetailsSetGet = arrayListCustomer.get(i);
objCust = new JSONObject();
try {
objCust.put("CustomerId", customerDetailsSetGet.getCustomerID());
objCust.put("PoolGuyId", customerDetailsSetGet.getPoolGuyId());
} catch (JSONException e) {
}
ArrayList<JobHistorySetGet> arrayListjobHistory = new ArrayList<>();
jobHistoryTable = new JobHistoryTable(con);
jobHistoryTable.open();
arrayListjobHistory = jobHistoryTable.getJobsAsPerCustId(customerDetailsSetGet.getCustomerID());
jobHistoryTable.close();
JSONObject objJobHis = null;
JSONArray jsonArrayJob = new JSONArray();
for (int j = 0; j < arrayListjobHistory.size(); j++) {
jobHistorySetGet = arrayListjobHistory.get(j);
objJobHis = new JSONObject();
try {
objJobHis.put("FilterChangeId", jobHistorySetGet.getFilterChangeId());
objJobHis.put("CustomerId", jobHistorySetGet.getCustomerId());
} catch (JSONException e) {
}
ArrayList<ReminderSetGet> arrayListReminder = new ArrayList<>();
reminderTable = new ReminderTable(con);
reminderTable.open();
arrayListReminder = reminderTable.getReminderAsPerJobID(jobHistorySetGet.getId());
reminderTable.close();
JSONArray jsonArrayReminder = new JSONArray();
JSONObject objReminder = null;
for (int k = 0; k < arrayListReminder.size(); k++) {
reminderSetGet = arrayListReminder.get(k);
objReminder = new JSONObject();
try {
Log.d("Anuj", "9");
objReminder.put("ReminderId", reminderSetGet.getReminderId());
objReminder.put("FilterChangeId", reminderSetGet.getFilterChangeId());
objReminder.put("CustomerId", reminderSetGet.getCustomerId());
jsonArrayReminder.put(objReminder);
} catch (JSONException e) {
}
}
objJobHis.put("Reminders", jsonArrayJob.toString());
jsonArrayJob.put(objJobHis);
}
objCust.putOpt("FilterChanges", jsonArrayJob.toString());
jsonArrayCust.put(objCust);
}
JSONObject finalobject = new JSONObject();
finalobject.put("Final", jsonArrayCust.toString());
} catch (SQLException e) {
e.printStackTrace();
} catch (JSONException e) {
e.printStackTrace();
}catch (Exception e) {
e.printStackTrace();
}
我的要求是等級秩序意味着可能有多個客戶表,並在每一個客戶表中會有多個作業,然後在每一個工作崗位,將有多個提醒
請張貼你已經嘗試過 – Emil
張貼的JSON是不是JSON – Vishwa
JSON格式correct.please看是不正確的..please首先確認您的JSON格式的代碼...使用http:// jsonlint。 com/ –