IV'ed Essayez de convertir JSONOBJECT en JSONARRAY et sa marque d'erreur pour l'erreur Typemismacth. J'essaie de comprendre ce qui se passe mais j'ai cru dessus.
{ "data":{ "c_correctCount":"0", "c_total":"0", "r_correctCount":"0", "r_total":"0", "p_correctCount":"0", "p_total":"0", "i_correctCount":"0", "i_total":"0" } }
3 Réponses :
Vous ne pouvez pas traiter Data Strong> en tant que JSONARRAY, car il est clair que Si votre objectif final est de regrouper toutes les deux paires partageant le même préfixe de la lettre dans un JSONObject et de les envelopper dans un JSONARRAY, vous devez le faire manuellement p>
Vérifiez cette solution
//this is the jsonobject which is getting from server JSONObject dataObj= json.getJSONObject("data"); Iterator x = dataObj.keys(); //here we are creating jsonArray object JSONArray jsonArray = new JSONArray(); //by looping Iterator converting jsonobject to jsonarray while (x.hasNext()){ String key = (String) x.next(); jsonArray.put(dataObj.get(key)); }
Veuillez essayer ci-dessous le code
private void prepareReportList(String reportList) { try { JSONObject task_type_list = null; try { task_type_list = new JSONObject(reportList); JSONObject jObjData = task_type_list.getJSONObject("data"); Iterator iterator = jObjData.keys(); while (iterator.hasNext()) { try { String key = (String) iterator.next(); JSONObject obj = jObjData.getJSONObject(key); addReportData(obj); } catch (Exception e) { e.getStackTrace(); } } } catch (JSONException e) { e.printStackTrace(); } } finally { setDataValuesToView(caregiverReportList); } }
Comment j'ai corrigé ce i>
Data code> doit être un tableau JSON (
[...] code>) non un objet JSON (
{... } code>) ... (ou vous pourriez analyser comme objet non tuyau)