0

I´m parsing JSON for my Android app but I am not able to get data, I am locked, I can´t see my issue, somebody can help me? This is my code, In log cat I get the message, "No value for ticket_price"

 private class DownloadJSON extends AsyncTask<Void, Void, Void> {

                @Override
                protected void onPreExecute() {
                    super.onPreExecute();
                    // Create a progressdialog
                    mProgressDialog = new ProgressDialog(getActivity());
                    // Set progressdialog title
                    //mProgressDialog.setTitle("Android JSON Parse Tutorial");
                    // Set progressdialog message
                    mProgressDialog.setMessage("Actualizando...");
                    mProgressDialog.setIndeterminate(false);
                    // Show progressdialog
                    mProgressDialog.show();
                }

                @Override
                protected Void doInBackground(Void... params) {
                    // Create an array
                    arraylist = new ArrayList<HashMap<String, String>>();
                    // Retrieve JSON Objects from the given URL address
                    jsonobject = JSONfunctions
                            .getJSONfromURL("url");

                    try {
                        // Locate the array name in JSON
                        if(jsonobject == null) 
                            return null; 

                        JSONObject subObjuno = jsonobject.getJSONObject("response");

                        jsonMainNode = subObjuno.getJSONArray("gigs");



                        for (int i = 0; i < jsonMainNode.length(); i++) {
                            HashMap<String, String> map = new HashMap<String, String>();
                            jsonobjectdos = jsonMainNode.getJSONObject(i);
                            // Retrive JSON Objects

                            map.put("name", jsonobjectdos.getString("name"));



                            //BLOQUE ARTISTS
                            jsonarraydos = jsonobjectdos.getJSONArray("artists");

                            for (int j = 0; j < jsonarraydos.length(); j++){
                                jsonobjectres = jsonarraydos.getJSONObject(i);

                                map.put("url", jsonobjectres.getString("url"));
                                map.put("art_logo", jsonobjectres.getString("art_logo"));
                            }

                            //BLOQUE VENUE
                            JSONObject subObj = jsonobjectdos.getJSONObject("venue");
                            map.put("name", subObj.getString("name"));
                            map.put("venue_logo", subObj.getString("venue_logo"));


                            JSONObject subObjdos = subObj.getJSONObject("location");
                            map.put("city", subObjdos.getString("city"));
                            map.put("country", subObjdos.getString("country"));
                            map.put("street", subObjdos.getString("street"));
                            map.put("postalcode", subObjdos.getString("postalcode"));
                            map.put("latitude", subObjdos.getString("latitude"));
                            map.put("longitude", subObjdos.getString("longitude"));

                            map.put("url", subObj.getString("url"));


                            map.put("tickets_url", jsonobjectdos.getString("tickets_url"));

                            //PRECIO
                            JSONObject subObjtres = jsonobjectdos.getJSONObject("ticket_price");
                            map.put("min", subObjtres.getString("min"));
                            map.put("max", subObjtres.getString("max"));

                            map.put("startDate", jsonobjectdos.getString("startDate"));
                            map.put("description", jsonobjectdos.getString("description"));

                            //IMAGES
                            JSONObject subObjtcuatro = jsonobjectdos.getJSONObject("images");
                            map.put("large", subObjtcuatro.getString("large"));


                            arraylist.add(map);
                        }
                    } catch (JSONException e) {
                        Log.e("Error", e.getMessage());
                        e.printStackTrace();
                    }
                    return null;
                }

                @Override
                protected void onPostExecute(Void args) {

                    if(arraylist == null || arraylist.size() == 0){
                         new DownloadJSON().execute();
                         mProgressDialog.dismiss();
                         return;
                    }
                    // Locate the listview in listview_main.xml
                    listview = (ListView) getActivity().findViewById(R.id.lista_horarios_liga);
                    // Pass the results into ListViewAdapter.java
                    adapter = new LazyAdapterConciertosCiudad(getActivity(), arraylist, "fonts/Roboto-Thin.ttf", "fonts/Roboto-Medium.ttf");
                    // Set the adapter to the ListView
                    listview.setAdapter(adapter);
                    // Close the progressdialog
                    mProgressDialog.dismiss();
                }
            }

The json result from the url is like this:

{"status": "success", "response": 
{"gigs": [
{
"id": 2025081,
"name": "Fink",
"artists": [
{
"id": "45329",
"url": "http://www.nvivo.es/artistas/Fink",
"name": "Fink",
"art_logo": "http://d36jiqg3u1m7g0.cloudfront.net/artistas/131x131/v2_131_thumb_45329_fink.jpg"
}],
"venue": {
"id": 11,
"name": "Kafe Antzokia",
"venue_logo": "http://d36jiqg3u1m7g0.cloudfront.net/salas/143x91/v2_143x91_thumb_11_kabsarrera.jpg",
"location": {
"city": "Bilbao",

"country": "Spain",
"street": "Calle San Vicente, 2",
"postalcode": "48001",
"latitude": "43.2637",
"longitude": "-2.92805"},
"url": "http://www.nvivo.es/kafe-antzokia-salas-11"
},

"tickets_url": "http://www.nvivo.es/conciertos/Fink-Bilbao",
"ticket_price": {
"min": 16.00,
"max": 16.00},
"startDate": "2015-03-13 22:00:00",
"modDate": "2015-03-13 20:02:50",
"description": "",
"images": {
"small": "http://d36jiqg3u1m7g0.cloudfront.net/artistas/80x80/v2_80_thumb_45329_fink.jpg",
"medium": "http://d36jiqg3u1m7g0.cloudfront.net/artistas/131x131/v2_131_thumb_45329_fink.jpg",
"large": "http://d36jiqg3u1m7g0.cloudfront.net/artistas/338x236/v2_338x236_thumb_45329_fink.jpg"
},
"attendance": "0",
"tag": "fivegig:gig=2025081",
"url": "http://www.nvivo.es/conciertos/Fink-Bilbao"

},

{
"id": 2214468,
"name": "Jesús Sangui",
"artists": [
{
"id": "5112572",
"url": "http://www.nvivo.es/artistas/Jes%C3%BAs+Sangui",
"name": "Jesús Sangui",
"art_logo": ""
}],
"venue": {
"id": 33738,
"name": "Café La Granja",
"venue_logo": "",
"location": {
"city": "Bilbao",

"country": "Spain",
"street": "Plaza Circular, 3",
"postalcode": "",
"latitude": "43.2614",
"longitude": "-2.92733"},
"url": "http://www.nvivo.es/cafe-la-granja-salas-33738"
},
"startDate": "2015-03-13 22:00:00",
"modDate": "2015-02-26 18:49:00",
"description": "",
"images": {
"small": "",
"medium": "",
"large": ""
},
"attendance": "0",
"tag": "fivegig:gig=2214468",
"url": "http://www.nvivo.es/conciertos/Jes%C3%BAs+Sangui-Bilbao"

},

{
"id": 2218606,
"name": "Sumrrá",
"artists": [
{
"id": "741214",
"url": "http://www.nvivo.es/artistas/Sumrr%C3%A1",
"name": "Sumrrá",
"art_logo": "http://d36jiqg3u1m7g0.cloudfront.net/artistas/131x131/v2_131_thumb_741214_sumrr__.jpg"
}],
"venue": {
"id": 128886,
"name": "La Ribera",
"venue_logo": "",
"location": {
"city": "Bilbao",

"country": "Spain",
"street": "Erribera Kalea, 20, 48005 Bilbao, Bizkaia, España",
"postalcode": "",
"latitude": "43.2563",
"longitude": "-2.92513"},
"url": "http://www.nvivo.es/la-ribera-salas-128886"
},
"startDate": "2015-03-14 00:00:00",
"modDate": "2015-02-27 14:09:40",
"description": "",
"images": {
"small": "http://d36jiqg3u1m7g0.cloudfront.net/artistas/80x80/v2_80_thumb_741214_sumrr__.jpg",
"medium": "http://d36jiqg3u1m7g0.cloudfront.net/artistas/131x131/v2_131_thumb_741214_sumrr__.jpg",
"large": "http://d36jiqg3u1m7g0.cloudfront.net/artistas/338x236/v2_338x236_thumb_741214_sumrr__.jpg"
},
"attendance": "1",
"tag": "fivegig:gig=2218606",
"url": "http://www.nvivo.es/conciertos/Sumrr%C3%A1-Bilbao"

},

{
"id": 1997788,
"name": "Lagwagon, The Flatliners, Western Addiction",
"artists": [
{
"id": "220494",
"url": "http://www.nvivo.es/artistas/Lagwagon",
"name": "Lagwagon",
"art_logo": "http://d36jiqg3u1m7g0.cloudfront.net/artistas/131x131/v2_131_thumb_220494_lagwagon_gira_conciertos_abr.jpg"
},
{
"id": "196192",
"url": "http://www.nvivo.es/artistas/The+Flatliners",
"name": "The Flatliners",
"art_logo": "http://d36jiqg3u1m7g0.cloudfront.net/artistas/131x131/v2_131_thumb_196192_flatliners1_web.jpg"
},
{
"id": "158123",
"url": "http://www.nvivo.es/artistas/Western+Addiction",
"name": "Western Addiction",
"art_logo": "http://d36jiqg3u1m7g0.cloudfront.net/artistas/131x131/v2_131_thumb_158123_western_addiction.jpg"
}],
"venue": {
"id": 200,
"name": "Santana 27",
"venue_logo": "http://d36jiqg3u1m7g0.cloudfront.net/salas/143x91/v2_143x91_thumb_200_ficha_foto_santana27.jpg",
"location": {
"city": "Bilbao",

"country": "Spain",
"street": "Calle Tellería, 27",
"postalcode": "",
"latitude": "43.2824",
"longitude": "-2.98176"},
"url": "http://www.nvivo.es/santana-27-salas-200"
},

"tickets_url": "http://www.nvivo.es/conciertos/Lagwagon-Bilbao",
"ticket_price": {
"min": 22.00,
"max": 52.74},
"startDate": "2015-03-14 19:00:00",
"modDate": "2015-03-13 21:02:24",
"description": "",
"images": {
"small": "http://d36jiqg3u1m7g0.cloudfront.net/carteles/62x62/v2_62_thumb__lagwagon_flatliners_vans_tou.jpg",
"medium": "http://d36jiqg3u1m7g0.cloudfront.net/carteles/131x131/v2_131_thumb__lagwagon_flatliners_vans_tou.jpg",
"large": "http://d36jiqg3u1m7g0.cloudfront.net/carteles/239xY/v2_239xY_thumb__lagwagon_flatliners_vans_tou.jpg"
},
"attendance": "1",
"tag": "fivegig:gig=1997788",
"url": "http://www.nvivo.es/conciertos/Lagwagon-Bilbao"

},

{
"id": 2025097,
"name": "Maika Makovski",
"artists": [
{
"id": "256064",
"url": "http://www.nvivo.es/artistas/Maika+Makovski",
"name": "Maika Makovski",
"art_logo": "http://d36jiqg3u1m7g0.cloudfront.net/artistas/131x131/v2_131_thumb_256064_maika_makovski.jpg"
}],
"venue": {
"id": 11,
"name": "Kafe Antzokia",
"venue_logo": "http://d36jiqg3u1m7g0.cloudfront.net/salas/143x91/v2_143x91_thumb_11_kabsarrera.jpg",
"location": {
"city": "Bilbao",

"country": "Spain",
"street": "Calle San Vicente, 2",
"postalcode": "48001",
"latitude": "43.2637",
"longitude": "-2.92805"},
"url": "http://www.nvivo.es/kafe-antzokia-salas-11"
},

"tickets_url": "http://www.nvivo.es/conciertos/Maika+Makovski-Bilbao",
"ticket_price": {
"min": 15.00,
"max": 15.00},
"startDate": "2015-03-14 22:00:00",
"modDate": "2015-03-13 20:03:02",
"description": "",
"images": {
"small": "http://d36jiqg3u1m7g0.cloudfront.net/artistas/80x80/v2_80_thumb_256064_maika_makovski.jpg",
"medium": "http://d36jiqg3u1m7g0.cloudfront.net/artistas/131x131/v2_131_thumb_256064_maika_makovski.jpg",
"large": "http://d36jiqg3u1m7g0.cloudfront.net/artistas/338x236/v2_338x236_thumb_256064_maika_makovski.jpg"
},
"attendance": "0",
"tag": "fivegig:gig=2025097",
"url": "http://www.nvivo.es/conciertos/Maika+Makovski-Bilbao"

},

{
"id": 2275759,
"name": "Ray Fernandez",
"artists": [
{
"id": "5112819",
"url": "http://www.nvivo.es/artistas/Ray+Fernandez",
"name": "Ray Fernandez",
"art_logo": ""
}],
"venue": {
"id": 11,
"name": "Kafe Antzokia",
"venue_logo": "http://d36jiqg3u1m7g0.cloudfront.net/salas/143x91/v2_143x91_thumb_11_kabsarrera.jpg",
"location": {
"city": "Bilbao",

"country": "Spain",
"street": "Calle San Vicente, 2",
"postalcode": "48001",
"latitude": "43.2637",
"longitude": "-2.92805"},
"url": "http://www.nvivo.es/kafe-antzokia-salas-11"
},

"tickets_url": "http://www.nvivo.es/conciertos/Ray+Fernandez-Bilbao",
"ticket_price": {
"min": 8.00,
"max": 8.00},
"startDate": "2015-03-15 19:00:00",
"modDate": "2015-03-13 20:03:14",
"description": "",
"images": {
"small": "",
"medium": "",
"large": ""
},
"attendance": "0",
"tag": "fivegig:gig=2275759",
"url": "http://www.nvivo.es/conciertos/Ray+Fernandez-Bilbao"

},

{
"id": 2020784,
"name": "Joan Baez",
"artists": [
{
"id": "155807",
"url": "http://www.nvivo.es/artistas/Joan+Baez",
"name": "Joan Baez",
"art_logo": "http://d36jiqg3u1m7g0.cloudfront.net/artistas/131x131/v2_131_thumb_155807_imagen_2.jpg"
}],
"venue": {
"id": 886,
"name": "Palacio Euskalduna",
"venue_logo": "http://d36jiqg3u1m7g0.cloudfront.net/salas/143x91/v2_143x91_thumb_886_palacio_euskalduna.jpg",
"location": {
"city": "Bilbao",

"country": "Spain",
"street": "Avenida Abandoibarra, 4",
"postalcode": "",
"latitude": "43.2688",
"longitude": "-2.93732"},
"url": "http://www.nvivo.es/palacio-euskalduna-salas-886"
},

"tickets_url": "http://www.nvivo.es/conciertos/Joan+Baez-Bilbao",
"ticket_price": {
"min": 120.00,
"max": 120.00},
"startDate": "2015-03-17 00:00:00",
"modDate": "2015-03-13 21:02:46",
"description": "",
"images": {
"small": "http://d36jiqg3u1m7g0.cloudfront.net/artistas/80x80/v2_80_thumb_155807_imagen_2.jpg",
"medium": "http://d36jiqg3u1m7g0.cloudfront.net/artistas/131x131/v2_131_thumb_155807_imagen_2.jpg",
"large": "http://d36jiqg3u1m7g0.cloudfront.net/artistas/338x236/v2_338x236_thumb_155807_imagen_2.jpg"
},
"attendance": "0",
"tag": "fivegig:gig=2020784",
"url": "http://www.nvivo.es/conciertos/Joan+Baez-Bilbao"

},

{
"id": 2103269,
"name": "El Pimiento Indomable",
"artists": [
{
"id": "5111770",
"url": "http://www.nvivo.es/artistas/El+Pimiento+Indomable",
"name": "El Pimiento Indomable",
"art_logo": ""
}],
"venue": {
"id": 11,
"name": "Kafe Antzokia",
"venue_logo": "http://d36jiqg3u1m7g0.cloudfront.net/salas/143x91/v2_143x91_thumb_11_kabsarrera.jpg",
"location": {
"city": "Bilbao",

"country": "Spain",
"street": "Calle San Vicente, 2",
"postalcode": "48001",
"latitude": "43.2637",
"longitude": "-2.92805"},
"url": "http://www.nvivo.es/kafe-antzokia-salas-11"
},

"tickets_url": "http://www.nvivo.es/conciertos/El+Pimiento+Indomable-Bilbao",
"ticket_price": {
"min": 15.00,
"max": 15.00},
"startDate": "2015-03-18 22:00:00",
"modDate": "2015-03-13 14:03:18",
"description": "",
"images": {
"small": "",
"medium": "",
"large": ""
},
"attendance": "0",
"tag": "fivegig:gig=2103269",
"url": "http://www.nvivo.es/conciertos/El+Pimiento+Indomable-Bilbao"

},

{
"id": 2209200,
"name": "The Limboos",
"artists": [
{
"id": "5090540",
"url": "http://www.nvivo.es/artistas/The+Limboos",
"name": "The Limboos",
"art_logo": ""
}],
"venue": {
"id": 11,
"name": "Kafe Antzokia",
"venue_logo": "http://d36jiqg3u1m7g0.cloudfront.net/salas/143x91/v2_143x91_thumb_11_kabsarrera.jpg",
"location": {
"city": "Bilbao",

"country": "Spain",
"street": "Calle San Vicente, 2",
"postalcode": "48001",
"latitude": "43.2637",
"longitude": "-2.92805"},
"url": "http://www.nvivo.es/kafe-antzokia-salas-11"
},

"tickets_url": "http://www.nvivo.es/conciertos/The+Limboos-Bilbao",
"ticket_price": {
"min": 10.00,
"max": 10.00},
"startDate": "2015-03-18 23:00:00",
"modDate": "2015-03-13 20:02:51",
"description": "",
"images": {
"small": "",
"medium": "",
"large": ""
},
"attendance": "0",
"tag": "fivegig:gig=2209200",
"url": "http://www.nvivo.es/conciertos/The+Limboos-Bilbao"

},

{
"id": 2095852,
"name": "Carvin Jones Band, Jimmy Barnatán",
"artists": [
{
"id": "257422",
"url": "http://www.nvivo.es/artistas/Carvin+Jones+Band",
"name": "Carvin Jones Band",
"art_logo": "http://d36jiqg3u1m7g0.cloudfront.net/artistas/131x131/v2_131_thumb_257422_carvinjonesband1_web.jpg"
},
{
"id": "5035961",
"url": "http://www.nvivo.es/artistas/Jimmy+Barnat%C3%A1n",
"name": "Jimmy Barnatán",
"art_logo": ""
}],
"venue": {
"id": 11,
"name": "Kafe Antzokia",
"venue_logo": "http://d36jiqg3u1m7g0.cloudfront.net/salas/143x91/v2_143x91_thumb_11_kabsarrera.jpg",
"location": {
"city": "Bilbao",

"country": "Spain",
"street": "Calle San Vicente, 2",
"postalcode": "48001",
"latitude": "43.2637",
"longitude": "-2.92805"},
"url": "http://www.nvivo.es/kafe-antzokia-salas-11"
},

"tickets_url": "http://www.nvivo.es/conciertos/Carvin+Jones+Band-Bilbao",
"ticket_price": {
"min": 12.00,
"max": 12.00},
"startDate": "2015-03-19 21:00:00",
"modDate": "2015-03-13 20:02:34",
"description": "",
"images": {
"small": "http://d36jiqg3u1m7g0.cloudfront.net/artistas/80x80/v2_80_thumb_257422_carvinjonesband1_web.jpg",
"medium": "http://d36jiqg3u1m7g0.cloudfront.net/artistas/131x131/v2_131_thumb_257422_carvinjonesband1_web.jpg",
"large": "http://d36jiqg3u1m7g0.cloudfront.net/artistas/338x236/v2_338x236_thumb_257422_carvinjonesband1_web.jpg"
},
"attendance": "1",
"tag": "fivegig:gig=2095852",
"url": "http://www.nvivo.es/conciertos/Carvin+Jones+Band-Bilbao"

}]}}
Elena
  • 181
  • 2
  • 12

1 Answers1

0

It might simply be that your data has no "ticket_price" for some gigs. In that case, you may want to consider optString

You can quickly explore your json in the Javascript console feature in most browsers.

Just pop your json into a var

var str = {"your_json" : "here"}

Then you can do something like this..

for (var gig in str.response.gigs){        
   console.log(str.response.gigs[gig].ticket_price);
}

And see some output like this

Object {min: 16, max: 16}
undefined
Object {min: 22, max: 52.74}
Object {min: 15, max: 15}
Object {min: 8, max: 8}
Object {min: 120, max: 120}
Object {min: 15, max: 15}
Object {min: 10, max: 10}
Object {min: 12, max: 12}

In addition, you could consider looking for other methods of parsing Json. For example Converting JSON to Java

Community
  • 1
  • 1
puj
  • 770
  • 5
  • 9