我在寫JSON,但我並沒有做出正確的格式 它給我的只有用戶和最後一個屬性項的拳頭屬性,而不是給我完整的JSON .. 提前感謝.. 我的代碼是在陣列JSON沒有給我競爭的格式,
JSONObject json = new JSONObject();
try {
JSONObject subJson = new JSONObject();
//JSONArray jsonArray = new JSONArray();
subJson.put("saleManId", LogIn.UserId);
subJson.put("customerId", LogIn.CustomerId);
json.put("User", subJson);
for (int i = 0; i < LogIn.subValues.length; i++) {
JSONObject subSubObj = new JSONObject();
for (int j = 0; j < LogIn.subValues[i].length; j++) {
if (LogIn.subValues[i][j] > 0) {
JSONObject item = new JSONObject();
item.put("itemID", LogIn.subIds[i][j]);
item.put("qty", LogIn.subValues[i][j]);
subSubObj.put("item", item);
}
}
if(subSubObj.length()>0)
{
json.put("orderDetail", subSubObj);
Log.d("json", json.toString());
}
}
Log.d("jsonnnnnnnnnnnnnnnnnnnnnnnnnnnnn", json.toString());
} catch (JSONException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
他們是30到35項,但它給我的只有這
{"orderDetail":{"item":{"qty":1,"itemID":"60"}},"User":{"customerId":"460","saleManId":"1"}}
你需要一個JSONArray如果一個地方你想要的對象的集合 – gpasci 2013-03-19 08:13:30
JSONArray只需要值,但我需要鍵也.. – 2013-03-19 08:31:01
一個JSONObject可以有隻有一個值給定的鍵... – njzk2 2013-03-19 08:39:54