How can I show the Json Parse Value in Android? -
i trying parsing , view json data. data not showing on device. can many times, in case can't.
here code:
@override protected void doinbackground(void... params) { // create array arraylist = new arraylist<hashmap<string, string>>(); // retrieve json objects given url address jsonobject = jsonfunctions.getjsonfromurl("https://www.googleapis.com/youtube/v3/search?part=id%2csnippet&order=viewcount&q=minecraft+mods&maxresults=50&key=<redacted>"); try { // locate array name in json jsonarray jsonarray = jsonobject.getjsonarray("items"); (int = 0; < jsonarray.length(); i++) { hashmap<string, string> map = new hashmap<string, string>(); jsonobject = jsonarray.getjsonobject(i); // retrive json objects jsonobject jsonobjid = jsonobject.getjsonobject("id"); map.put("videoid", jsonobjid.getstring("videoid")); jsonobject jsonobjsnippet = jsonobject.getjsonobject("snippet"); map.put("title", jsonobjsnippet.getstring("title")); //map.put("description", jsonobjsnippet.getstring("description")); // map.put("flag", jsonobject.getstring("flag")); jsonobject jsonobjthumbnail = jsonobjsnippet.getjsonobject("thumbnails"); string imgurl = jsonobjthumbnail.getjsonobject("high").getstring("url"); map.put("url",imgurl); // set json objects array arraylist.add(map); } } catch (jsonexception e) { log.e("error", e.getmessage()); e.printstacktrace(); } return null; } here json respons
{ "items": [ { "kind": "youtube#searchresult", "etag": "\"abqhwywil_aknqdqji7_fqik-u4/sylqor4h5rdfr24l2b2rlpg5lwa\"", "id": { "kind": "youtube#channel", "channelid": "uch-_hzb2ilsco9ftvsnrciq" }, "snippet": { "publishedat": "2008-07-09t21:56:56.000z", "channelid": "uch-_hzb2ilsco9ftvsnrciq", "title": "yogscast lewis & simon", "description": "minecraft , multiplayer comedy gaming drunken dwarf , handsome spaceman! join laugh our way through best, worst , ...", "thumbnails": { "default": { "url": "https://yt3.ggpht.com/-fmo2nso2pp8/aaaaaaaaaai/aaaaaaaaaaa/qzlwwqsqmiu/s512-c-k-no/photo.jpg" }, "medium": { "url": "https://yt3.ggpht.com/-fmo2nso2pp8/aaaaaaaaaai/aaaaaaaaaaa/qzlwwqsqmiu/s512-c-k-no/photo.jpg" }, "high": { "url": "https://yt3.ggpht.com/-fmo2nso2pp8/aaaaaaaaaai/aaaaaaaaaaa/qzlwwqsqmiu/s512-c-k-no/photo.jpg" } }, "channeltitle": "bluexephos", "livebroadcastcontent": "none" } }] }
as can see in image below, there no "videoid" key in jsonobject jsonobjid.
you'll have null value in map object "videoid" key. why data not shown.
ps: use model class instead of hashmap, it'll more elegant.

Comments
Post a Comment