[英]How to parse a JSON in a JSON
我正在为医疗应用程序创建一个mcq,并且尝试使用此JSON从其他数据库中选择不同的问题:
{
"QCM": [{
"question": "Est-ce que Guillaume a pris?",
"id": "34",
"choix": ["Oui", "Non"]
}]
}
然后我将我的问题字符串传递到textview中,如果我有2个选择,则仅创建2个按钮,但是仅创建1个按钮,在我的按钮中,我具有以下字符串:
["Oui", "Non"]
所以我不明白,因为我为其创建了第二个JSONArray循环...
这是我的Java
try
{
JSONArray QCM = response.getJSONArray("QCM");
for (int i=0; i<QCM.length(); i++) {
JSONObject getQcmObject = QCM.getJSONObject(i);
String questionGet = getQcmObject.getString("question");
symptomesQuestions.setText(questionGet);
for (int x=0; x<QCM.length(); x++){
JSONObject getChoixObject = QCM.getJSONObject(x);
String choiceGet = getChoixObject.getString("choix");
lesChoixButton.setText(choiceGet);
}
}
如果有人可以解释我该怎么做,我想学习! 找不到此类请求的任何示例。 谢谢大家!
您使用了错误的解析器,请按如下所示更改它:
JSONArray QCM = response.getJSONArray("QCM");
for (int i = 0; i < QCM.length(); i++) {
JSONObject getQcmObject = QCM.getJSONObject(i);
String questionGet = getQcmObject.getString("question");
symptomesQuestions.setText(questionGet);
JSONArray choiceGet = getChoixObject.getJSONArray("choix");
lesChoixButton1.setText(choiceGet.getString(0));
lesChoixButton2.setText(choiceGet.getString(1));
}
使用此站点从您的json创建java pojo模型: http : //www.jsonschema2pojo.org/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.