我有一个JSONArray
,看起来像这样:JSONArray为String在Java中
我怎样才能将其转换成字符串?
,如果我尝试:
json.toString();
字符串为:
["[email protected]","[email protected]","[email protected]","[email protected]","[email protected]","[email protected]","[email protected]"]
,但我想是这样的:
{
"json":
"values": [
{
"answer": "true",
"remark":"",
"questionId": "0"
"checklistId": "2"
},
{
"answer": "true",
"remark":"",
"questionId": "0"
"checklistId": "2"
}
]
}
编辑:
这个剪断如何我使json数组:
if(cb.isChecked() || !text.getText().toString().equals("")){
ChecklistAnswer answer = new ChecklistAnswer(questions.get(id).id, 2, cb.isChecked(), text.getText().toString());
answers.add(answer);
}
}
JSONArray json = new JSONArray(answers);
String jsonString = json.toString();
显示你的代码 – 2014-11-06 09:51:51
它按预期工作......你只要把'的一些片断ChecklistAnswer'对象到数组......不是'JSONObject' ...'ChecklistAnswer.toString()'返回“[email protected]”...所以要么覆盖ChecklistAnswer.toString方法返回json字符串,要么创建函数将ChecklistAnswer转换为JSOObject – Selvin 2014-11-06 09:51:52
显示代码用于json解析 – 2014-11-06 09:54:20