我正在制作 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();
}
它们是 Array 中的 30 到 35 个项目,但它只给了我这个
{"orderDetail":{"item":{"qty":1,"itemID":"60"}},"User":{"customerId":"460","saleManId":"1"}}