代码如下:JSONObject jChild=new JSONObject();
JSONObject jParent=new JSONObject();
for (Product p : boxAdapter.getBox()) {
if (p.checked){
try {
jChild.put("uid", p.uid);
list.add(String.valueOf(jChild));
//list.add(String.valueOf(jParent));
} catch (JSONException e) {
e.printStackTrace();
}
}
}
jParent.put("users", list);
// Toast.makeText(this, ""+jParent, Toast.LENGTH_LONG).show();
Log.v("TakeAttendance","JSONpARENT "+String.valueOf(jParent));输出:{"users":"[{\"uid\":\"4\"}, {\"uid\":\"5\"}, {\"uid\":\"6\"}]"}我所需要的是:{users: [
{
name: "acx",
uid: "2"
},
{
name: "test",
uid: "6"
},
{
name: "ccc",
uid: "11"
}
]
}
2 回答

精慕HU
TA贡献1845条经验 获得超8个赞
private void jsonTest() {
try {
JSONObject json = new JSONObject();
JSONArray jsonArr = new JSONArray();
for (int i = 0; i < 3; i++) {
JSONObject arrObj = new JSONObject();
arrObj.put("name", "test");
arrObj.put("uid", i);
jsonArr.put(arrObj);
}
json.put("users", jsonArr);
Log.e("LH", "json==" + json); } catch (JSONException e) { e.printStackTrace(); } }

慕妹3242003
TA贡献1824条经验 获得超6个赞
只需要把上面那哥们的
Log.e("LH", "json==" + json);改成 Log.e("LH", "json==" + json.toString());
添加回答
举报
0/150
提交
取消