代码:
final HashMap<?,?> entryMap = (HashMap<?, ?>) getListView().getItemAtPosition(index);
System.out.println(entryMap.get("raw" ));
输出:
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”);
我能够获得what_2_url
的值但是如何在{raw = {handle = chai,postid = 54,
中获取值 link = (String)entryMap.get("postid");
它返回null如何使用java hashmap
获取值答案 0 :(得分:1)
首先使用getClass()
对link
(String)entryMap.get("what_2_url")
的值link
进行测试,然后打印它。然后将instanceof
转换为正确的类,并使用getter或为该特定类定义的任何内容。
在投射前使用HashMap<?, ?> linkHashMap = (HashMap<?, ?>) link;
System.out.println(linkHashMap.get("postid"));
的测试可能是一个好主意。
所以在你的情况下:
{{1}}