I'm having trouble trying to parse a json array string sent from Django to an Android. This is the format of the json string.
[
{
"pk": 1,
"model": "brete.brete",
"fields": {
"contenido": "93iw09if",
"fecha": "2011-05-07 03:06:40",
"codigo_confirmacion": "",
"correo": "[email protected]",
"activado": false,
"titulo": "234"
}
},
{
"pk": 2,
"model": "brete.brete",
"fields": {
"contenido": "asoidjfdiso",
"fecha": "2011-05-07 03:08:09",
"codigo_confirmacion": "",
"correo": "[email protected]",
"activado": false,
"titulo": "ijj"
}
}
]
etc
This is how I'm grabbing the data:
//parse json data
try{
JSONArray jArray = new JSONArray(result);
for(int i=0;i<jArray.length();i++){
JSONObject json_data = jArray.getJSONObject(i);
Brete resultRow = new Brete();
resultRow.contenido = json_data.getString("contenido");
resultRow.fecha = json_data.getString("fecha");
resultRow.correo = json_data.getString("correo");
arrayOfWebData.add(resultRow);
}
}
catch(JSONException e){
Log.e("log_tag", "Error parsing data "+e.toString());
}
I'm trying to get the data of 'contenido'
, 'fecha'
and 'correo'
But I'm not getting any rows displayed. This is not the whole code and maybe the problem lies somewhere else, but I have a hunch this might be a problem of not parsing correctly the nested json with json_data.getString(). Any help is appreciated.