2012-07-31 63 views
0

我有一个非常简单的问题,但我只想弄明白。从哈希映射中获取字符串

我希望能够从一个HashMap中拿出一些东西,但不能让它工作。

下面是代码:

try{ 

     JSONArray deelnemers = json.getJSONArray("deelnemers"); 

     int Key = getIntent().getIntExtra("Key", -1); 


      { HashMap<String, String> map = new HashMap<String, String>(); 
      JSONObject e = deelnemers.getJSONObject(Key); 

      map.put("id", String.valueOf(Key)); 
      map.put("name", "Naam: " + e.getString("naamingw2")); 
      map.put("sex", "Geslacht: " + e.getString("geslacht")); 
      map.put("rank", "Rang: " + e.getString("rang")); 
      map.put("picture", "http://www.de-saksen.nl/2/images/comprofiler/" + e.getString("avatar")); 
      mylist.add(map);    
     } 
      String URL = new String (mylist.get("picture")); 
      WebView WV = (WebView) findViewById(R.id.webView1);    
      WV.loadUrl(URL); 

我在得到一个compiller错误(mylist.get( “图片”));

+2

' “图片报”'是在'map',而不是在'mylist',我想。 – nullpotent 2012-07-31 09:12:53

+0

不应该是map.get(“picture”)或((HashMap)mylist.get(0))。get(“picture”) – krishnakumarp 2012-07-31 09:13:24

+0

错误是什么? – sunil 2012-07-31 09:13:52

回答

1

我可能会错过一些东西,但是你的HashMap的名字是“map”,而不是“mylist”。

编辑:如果MYLIST表示包含您的HashMap中的列表中,那么你就可以做到以下几点:

mylist.get(0).get("picture"); 
+0

String URL = mylist.get(0).get(“picture”);奇迹般有效 – 2012-07-31 09:16:52