
Parsear JSON
Publicado por Victor (3 intervenciones) el 26/06/2017 20:46:51
Buenas!!!!
Voy un poco perdido en este tema, estoy con este documento JSON y necesito sacar unos datos de el pero no se muy bien como esta montada esta estructura y me pierdo.
Link : http://api.wunderground.com/api/8fec2d58690a48bc/conditions/forecast/lang:CA/q/Spain/Sueca.json
Mi problema lo tengo al sacar los datos osea con este método
La parte en cursiva es donde me marca el error ya que no se como sacar los .getString("Nombre del campo") del JSON que dejo en link.Gracias!!!!.
Voy un poco perdido en este tema, estoy con este documento JSON y necesito sacar unos datos de el pero no se muy bien como esta montada esta estructura y me pierdo.
Link : http://api.wunderground.com/api/8fec2d58690a48bc/conditions/forecast/lang:CA/q/Spain/Sueca.json
Mi problema lo tengo al sacar los datos osea con este método
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
private void ParsetjaAJSON(String documentJSON){
Log.d(TAG, "Resposta2: " + documentJSON);
if(documentJSON!=null){
try {
JSONArray Dies = new JSONArray(documentJSON);
for (int i = 0; i<Dies.length();i++){
JSONObject jsonObject=Dies.getJSONObject(i);
String Dia = jsonObject.getString("date");
String titol = jsonObject.getString("title");
String titolnit = jsonObject.getString("title");
String precipitacions1 = jsonObject.getString("pop");
String precipitacions2 = jsonObject.getString("pop");
String descripcio1 = jsonObject.getString("fcttext_metric");
String descripcio2 = jsonObject.getString("fcttext_metric");
Dia dia = new Dia();
dia.setDia(Dia);
dia.setTitol(titol);
dia.setTitolnit(titolnit);
dia.setPrecipitacions1(precipitacions1);
dia.setPrecipitacions2(precipitacions2);
dia.setDescripcio1(descripcio1);
dia.setDescripcio2(descripcio2);
Log.d(TAG,dia.toString());
DiesParsetjats.add(dia);
}
} catch (JSONException e) {
Log.e(TAG, "Error parsejant Json: " + e.getMessage());
Snackbar.make(findViewById(R.id.activity_main),
"Error parsejant Json", Snackbar.LENGTH_LONG).show();
}
} else {
Log.e(TAG, "Error intentant rebre el Json.");
Snackbar.make(findViewById(R.id.activity_main),
"Error intentant rebre el Json.", Snackbar.LENGTH_LONG).show();
}
}
La parte en cursiva es donde me marca el error ya que no se como sacar los .getString("Nombre del campo") del JSON que dejo en link.Gracias!!!!.
Valora esta pregunta


0