string json =“ {"success": true, "yi18":[{"name":"头部","id":1},{"name":"其他","id":85}]}  ”
//
JSONObject  jsonObject= new JSONObject(json);jsonObject.getString("success");
JSONArray  _jsonArray =jsonObject.getJSONArray("yi18");for(int i=0 ;i<_jsonArray.length();i++){
JSONObject  jsonobj = (JSONObject) _jsonArray.opt(i);
jsonObject.getString("name");
jsonObject.getString("id");}

解决方案 »

  1.   

    里面包含两层数据,楼主可以去看看这个:http://www.andsos.com/?p=193
      

  2.   

    麻烦帮我看一下这是哪出错了?显示不chu来
    String result = "";
    private ListView listview;
    List<Map<String, String>> list = new ArrayList<Map<String, String>>();
    Map<String, String> map = null; protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.diseasefind);
    listview = (ListView) findViewById(R.id.listview1);
    parseJson(result);
    SimpleAdapter simpleAdapter = new SimpleAdapter(this, list,
    R.layout.sssss, new String[] { "name", "ip" }, new int[] {
    R.id.name, R.id.ip });
    listview.setAdapter(simpleAdapter); new Thread(new myThread()).start();
    } public List<Map<String, String>> parseJson(String jsondata) {
    try {
    JSONObject jsonObject = new JSONObject(jsondata);
    //Boolean success = jsonObject.getBoolean("success");
    jsonObject.getString("success");
    JSONArray jsonArray = jsonObject.getJSONArray("yi18");
    for (int i = 0; i < jsonArray.length(); i++) {
    JSONObject item = jsonArray.getJSONObject(i);
    String name = item.getString("name");
    int id = item.getInt("id");
    map = new HashMap<String, String>();
    map.put("id", id + "");
    map.put("name", name);
    list.add(map);
    }
    } catch (Exception e1) {
    // TODO Auto-generated catch block
    e1.printStackTrace();
    }
    return list;
    } class myThread implements Runnable {
    @Override
    public void run() {
    String httpUrl = "http://api.yi18.net/disease/department";
    // TODO Auto-generated method stub
    HttpGet httpGet = new HttpGet(httpUrl);
    try {
    HttpClient httpClient = new DefaultHttpClient();
    HttpResponse httpResponse = httpClient.execute(httpGet);
    if (httpResponse.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
    String strResult = EntityUtils.toString(httpResponse
    .getEntity());
    result = strResult.toString();
    }
    } catch (Exception e) {
    // TODO: handle exception
    e.printStackTrace();
    }
    }
      

  3.   

    麻烦帮我看一下这是哪出错了?显示不chu来
    String result = "";
    private ListView listview;
    List<Map<String, String>> list = new ArrayList<Map<String, String>>();
    Map<String, String> map = null; protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.diseasefind);
    listview = (ListView) findViewById(R.id.listview1);
    parseJson(result);
    SimpleAdapter simpleAdapter = new SimpleAdapter(this, list,
    R.layout.sssss, new String[] { "name", "ip" }, new int[] {
    R.id.name, R.id.ip });
    listview.setAdapter(simpleAdapter); new Thread(new myThread()).start();
    } public List<Map<String, String>> parseJson(String jsondata) {
    try {
    JSONObject jsonObject = new JSONObject(jsondata);
    //Boolean success = jsonObject.getBoolean("success");
    jsonObject.getString("success");
    JSONArray jsonArray = jsonObject.getJSONArray("yi18");
    for (int i = 0; i < jsonArray.length(); i++) {
    JSONObject item = jsonArray.getJSONObject(i);
    String name = item.getString("name");
    int id = item.getInt("id");
    map = new HashMap<String, String>();
    map.put("id", id + "");
    map.put("name", name);
    list.add(map);
    }
    } catch (Exception e1) {
    // TODO Auto-generated catch block
    e1.printStackTrace();
    }
    return list;
    } class myThread implements Runnable {
    @Override
    public void run() {
    String httpUrl = "http://api.yi18.net/disease/department";
    // TODO Auto-generated method stub
    HttpGet httpGet = new HttpGet(httpUrl);
    try {
    HttpClient httpClient = new DefaultHttpClient();
    HttpResponse httpResponse = httpClient.execute(httpGet);
    if (httpResponse.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
    String strResult = EntityUtils.toString(httpResponse
    .getEntity());
    result = strResult.toString();
    }
    } catch (Exception e) {
    // TODO: handle exception
    e.printStackTrace();
    }
    }
      

  4.   

    调用gson包,写一个类,映射过去,调用构造方法可解