android:从ArrayList中获取键值对
16lz
2021-01-23
直接上示例:
public void getList(String cmdStr, int index, int type, ArrayList> mList) { try { JSONArray gethotlist = new JSONObject(cmdStr).getJSONArray("list"); JSONObject jso = (JSONObject)gethotlist.opt(index); JSONArray jContent = jso.getJSONArray("content"); for (int j = 0; j < jContent.length(); j++) { JSONObject mJContent = (JSONObject)jContent.opt(j); HashMap map = new HashMap(); switch(type) { case 0: map.put("ItemTitle", getSecList(mJContent).name); System.out.println("name:"+getSecList(mJContent).name); break; case 1: map.put("ItemUrl", getSecList(mJContent).url); map.put("ItemTitle", getSecList(mJContent).name); System.out.println("url:"+getSecList(mJContent).url); System.out.println("name:"+getSecList(mJContent).name); break; case 2: map.put("ItemLen", getSecList(mJContent).len); System.out.println("len:"+getSecList(mJContent).len); break; default: break; } mList.add(map); } } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
private void test() { mDqJson.getList(cmdStr, index, GET_URL, urlList); if (!urlList.isEmpty()) { Iterator> it = urlList.iterator(); HashMap hash; Object value = new Object(); Object nameValue = new Object(); int i = 0; while(it.hasNext()) { hash = it.next(); HashMap map = new HashMap(); value = hash.get("ItemUrl"); nameValue = hash.get("ItemTitle"); System.out.println("value-url:"+value.toString()); System.out.println("value-name:"+nameValue.toString()); } } }
public void getList(String cmdStr, int index, int type, ArrayList
private void test() { mDqJson.getList(cmdStr, index, GET_URL, urlList); if (!urlList.isEmpty()) { Iterator
更多相关文章
- android倒计时控件示例
- Android部分控件示例汇总
- Android解析Excel文档完整示例
- Android裁剪图像实现方法示例
- Android手势操作示例(上/下/左/右的判断)
- Android ApiDemos示例解析(18):App->Activity->Wallpaper
- Android判断当前网络是否可用--示例代码
- android Shader类简介_渲染图像示例
- Android ApiDemos示例解析(9):App->Activity->Persistent State