android - jsonObject parsing issue "org.json.JSONException: No value for thumbnails" -


i've got little problem parsing json android app.
want thumbnail url , videoid shows no value thumbnails jsonexception ,
same happens videoid
how can do? please

this how json file , fragment activity looks like:

request url :

   https://www.googleapis.com/youtube/v3/playlists?part=snippet&channelid=uc_x5xg1ov2p6uzz5fsm9ttw&maxresults=1&key={your_api_key}     

json response :

    {         "kind": "youtube#playlistlistresponse",        "etag": "\"idqj1j7zks4x3o3zsflbowgwahu/qndwmfxnha--i54ealcsqnwg2ok\"",      "nextpagetoken": "caeqaa",        "pageinfo": {         "totalresults": 291,         "resultsperpage": 1        },        "items": [         {          "kind": "youtube#playlist",          "etag":"\"idqj1j7zks4x3o3zsflbowgwahu/ib0xo8j78ybzzvhqq59q2y8wofi\"",          "id": "plou2xlyxmsij79h65lupzarlyvmui-i7b",          "snippet": {          "publishedat": "2015-07-17t18:59:08.000z",          "channelid": "uc_x5xg1ov2p6uzz5fsm9ttw",   "title": "this week on google developers 7/11/15 - 7/17/15",   "description": "",   "thumbnails": {    "default": {     "url": "https://i.ytimg.com/vi/ygfe9pj5n60/default.jpg",     "width": 120,     "height": 90    },    "medium": {     "url": "https://i.ytimg.com/vi/ygfe9pj5n60/mqdefault.jpg",     "width": 320,     "height": 180    },       "position": 0,       "resourceid": {         "videoid": "1_hgnnfafm4"           }      }     }    ]   }   

fragment activity jsonresponse code :

   private void parsejsonreaponse(jsonobject response) {       if (response == null || response.length() == 0) {            return;       }       try {           stringbuilder data = new stringbuilder();         jsonarray arrayitems = response.getjsonarray(key_items);          (int = 0; < arrayitems.length(); i++) {             jsonobject currentitems = arrayitems.getjsonobject(i);             string id = currentitems.getstring(key_id);             //data.append(id + "\n");             jsonobject objectsnippet = currentitems.getjsonobject(key_snippet);             string title = null;             if (objectsnippet.has(key_title)) {                 title = objectsnippet.getstring(key_title);             }             else {                 title = "na";             }             //data.append(id + title + "\n\n");              jsonobject objectthumbnail = objectsnippet.getjsonobject(key_thumbnail);             jsonobject objectthumbnailmedium = objectthumbnail.getjsonobject(key_thumbnail_medium);             string urlthumbnail = null;             if (objectthumbnailmedium.has(key_thumbnail_medium)) {                 urlthumbnail = objectthumbnailmedium.getstring(key_thumbnail_medium_url);             }              jsonobject objectresourceid = objectsnippet.getjsonobject(key_resourceid);             string resourceid = null;             if (objectresourceid.has(key_videoid)){                 resourceid = objectresourceid.getstring(key_videoid);             }              videodata videodata = new videodata();             videodata.settitle(title);             videodata.seturlthumbnail(urlthumbnail);             videodata.setvideoid(resourceid);              listvideos.add(videodata);              data.append(id + title + urlthumbnail + resourceid +"\n\n");          }          l.t(getactivity(),listvideos.tostring());     //            l.t(getactivity(),data.tostring());      } catch (jsonexception e) {         e.printstacktrace();     } } 

here logcat msgs

    07-18 01:11:25.075    1823-1823/com.example.example w/system.err﹕ org.json.jsonexception: no value thumbnails        07-18 01:11:25.075    1823-1823/com.example.example w/system.err﹕ @ org.json.jsonobject.get(jsonobject.java:389)        07-18 01:11:25.075    1823-1823/com.example.example w/system.err﹕ @ org.json.jsonobject.getjsonobject(jsonobject.java:609)        07-18 01:11:25.075    1823-1823/com.example.example w/system.err﹕ @ com.example.example.fragment.videotabfragment.parsejsonreaponse(videotabfragment.java:110)        07-18 01:11:25.075    1823-1823/com.example.example w/system.err﹕ @ com.example.example.fragment.videotabfragment.access$000(videotabfragment.java:31)        07-18 01:11:25.075    1823-1823/com.example.example w/system.err﹕ @ com.example.example.fragment.videotabfragment$1.onresponse(videotabfragment.java:75)        07-18 01:11:25.076    1823-1823/com.example.example w/system.err﹕ @ com.example.example.fragment.videotabfragment$1.onresponse(videotabfragment.java:71)        07-18 01:11:25.076    1823-1823/com.example.example w/system.err﹕ @ com.android.volley.toolbox.jsonrequest.deliverresponse(jsonrequest.java:65)        07-18 01:11:25.076    1823-1823/com.example.example w/system.err﹕ @ com.android.volley.executordelivery$responsedeliveryrunnable.run(executordelivery.java:99)        07-18 01:11:25.076    1823-1823/com.example.example w/system.err﹕ @ android.os.handler.handlecallback(handler.java:739)        07-18 01:11:25.076    1823-1823/com.example.example w/system.err﹕ @ android.os.handler.dispatchmessage(handler.java:95)        07-18 01:11:25.076    1823-1823/com.example.example w/system.err﹕ @ android.os.looper.loop(looper.java:135)        07-18 01:11:25.076    1823-1823/com.example.example w/system.err﹕ @ android.app.activitythread.main(activitythread.java:5254)        07-18 01:11:25.076    1823-1823/com.example.example w/system.err﹕ @ java.lang.reflect.method.invoke(native method)        07-18 01:11:25.076    1823-1823/com.example.example w/system.err﹕ @ java.lang.reflect.method.invoke(method.java:372)        07-18 01:11:25.076    1823-1823/com.example.example w/system.err﹕ @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:903)        07-18 01:11:25.076    1823-1823/com.example.example w/system.err﹕ @ com.android.internal.os.zygoteinit.main(zygoteinit.java:698)     


Comments

Popular posts from this blog

qt - Using float or double for own QML classes -

Create Outlook appointment via C# .Net -

ios - Swift Array Resetting Itself -