Fetch a key value pair from raw value key value pair hashmap Java

Code:

 final HashMap<?,?> entryMap = (HashMap<?, ?>) getListView().getItemAtPosition(index);

System.out.println(entryMap.get("raw" ));

output :

03-04 00:35:33.301: I/System.out(20969): {raw={handle=chai, queued=false, claimable=false, oname=, obasetype=A, opostid=62, userid=11, moderatable=false, parentid=, unflaggable=false, upvotes=2, type=Q, isbyuser=false, deleteable=false, _type=A, flagcount=0, closeable=true, viewable=true, level=0, updated=, created=1393741365, closedbyid=, flagtohide=false, oemail=chan30kcr@yahoo.com, points=330, _time=1393854769, reshowimmed=false, commentable=false, _order_=11, extra=, oavatarblobid=, downvotes=0, followable=false, aselectable=true, lastip=, format=, netvotes=2, retagcatbutton=false, hotness=2.6352e+10, editable=true, _userid=11, ohandle=chai, content=How to register??, avatarwidth=, categoryid=, oavatarheight=, email=chan30kcr@yahoo.com, basetype=Q, answerbutton=true, lastuserid=, avatarheight=, postid=54, commentbutton=false, createip=223.227.82.64, acount=1, sort=-1393854769, olevel=0, hideable=true, selchildid=, oip=223.227.27.110, updatetype=, oavatarwidth=, avatarblobid=, cookieid=, lastviewip=122.167.118.113, oflags=1, title= .., otime=1393854769, reopenable=false, notify=, name=, userfavoriteq=0, userflag=0, closed=false, oflagcount=0, editbutton=true, ohidden=0, tags=, categorybackpath=, flags=1, flagbutton=true, categoryids=, opoints=330, clearflaggable=false, ocookieid=, uservote=1, views=3, hidden=0, reshowable=false, retagcatable=true, categoryname=, ouserid=11, authorlast=true}, closepost=, answers=[Ljava.lang.Object;@410576e0, what_2=answered, extravalue=, who_2={data=<a href="./index.php/user/chai" class="qa-user-link url nickname">chai</a>, title=, level=Registered user, points={data=330, suffix= points, prefix=}, suffix=false, prefix=by }, favorite=0, avatar=, vote_state=voted_up, who={data=<a href="./index.php/user/chai" class="qa-user-link url nickname">chai</a>, title=, level=Registered user, points={data=330, suffix= points, prefix=}, suffix=false, prefix=by }, meta_order=^what^when^where^who, content=How to register??, netvotes_raw=2, username=chan, when_2={data=5 hours, suffix= ago, prefix=}, what=asked, when={data=1 day, suffix= ago, prefix=}, what_2_url=./?show=62#a62, categories=[Ljava.lang.Object;@410579a0, parentquestion=, comments=[Ljava.lang.Object;@410577c8}

link = (String)entryMap.get("what_2_url");

I am able to get the value of what_2_url

but how to get the value inside the {raw={handle=chai, postid=54,

  link = (String)entryMap.get("postid");

it returns null how to fetch the value using java hashmap

Answers


First test what kind of object is returned by using getClass() on the value of link for (String)entryMap.get("what_2_url")and printing it. Then cast link to the right class and use a getter or anything defined for that specific class.

A test using instanceof before casting is probably a good idea.


So in your case:

HashMap<?, ?> linkHashMap = (HashMap<?, ?>) link;
System.out.println(linkHashMap.get("postid"));

Need Your Help

Get bigger profile picture of facebook friends

ios iphone facebook swift facebook-graph-api

I'm simply trying to get a list of facebook friends that have my app, along with their profile picture in decent quality, something higher than the default 50x50 image i'm getting.

In App Purchase Unique Identifying Data

iphone in-app-purchase

O.K so I'm writing a iPhone travel guide, you purchase a subscription to a travel guide for 3 months, it downloads a fairly hefty database and for 3 months that database gets updated weekly with new