json - Android - YouTube API get videoId from video list -


i want videoid in (items:[ id:{ ) shows org.json.jsonexception: no value videoid. there wrong code here?

items: [ {     kind: "youtube#searchresult",     etag: ""etag"",     id: {         kind: "youtube#video",         videoid: "nsvttbhym2e"     },     snippet: {         publishedat: "publishedat",         channelid: "channelid",         title: "title",         description: description",     thumbnails: {         default: {             url: "thumbnail url",             width: 120,             height: 90         },         medium: {             url: "thumbnail url",             width: 320,             height: 180         },         high: {             url: "thumbnail url",             width: 480,             height: 360         }     },     channeltitle: "channeltitle",     livebroadcastcontent: "none"     } }, 

this part of source code video id video list

jsonarray items = jsonobject.getjsonarray("items"); (int = 0; < items.length(); i++) {     jsonobject json_data = items.getjsonobject(i);     strvideoid = json_data.getjsonobject("id").getstring("videoid"); } 

first of all, providing invalid json, take notice etag , description have invalid values.

assuming have valid json data, can retrieve list of video ids values using following method:

private list<string> getvideoids(final jsonobject jsonobject) {     final list<string> videoidlist = new arraylist<>();     if (null != jsonobject) {         try {             final jsonarray itemarray = jsonobject.getjsonarray("items");             final int itemcount = itemarray.length();             (int = 0; < itemcount; ++i) {                 final jsonobject item = itemarray.getjsonobject(i);                 final jsonobject id = item.getjsonobject("id");                 final string videoid = id.getstring("videoid");                 videoidlist.add(videoid);             }         } catch (final jsonexception e) {             e.printstacktrace();         }     }     return videoidlist; } 

Comments

Popular posts from this blog

inversion of control - Autofac named registration constructor injection -

verilog - Systemverilog dynamic casting issues -

ios - Change Storyboard View using Seague -