コード:
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, [email protected], 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 protected], 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");
Javaハッシュマップを使用して値をフェッチする方法はnullを返します
まずgetClass()
、link
forの値を使用して(String)entryMap.get("what_2_url")
それを出力することにより、返されるオブジェクトの種類をテストします。次にlink
、適切なクラスにキャストし、ゲッターまたはその特定のクラスに定義されているものを使用します。
instanceof
キャストする前に使用するテストはおそらく良い考えです。
だからあなたの場合:
HashMap<?, ?> linkHashMap = (HashMap<?, ?>) link;
System.out.println(linkHashMap.get("postid"));
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加