{"user_info":{"province":"省",
"city":"城市","name":"名字",
"perid":"2009年12月01日至2009年12月31日"},
}
我希望把这样的格式数据写到bean中不知道怎么弄 有没有什么函数?

解决方案 »

  1.   

    创建一个json对象,把这字符串当成构造方法的参数传进去
    然后遍历Key,再写到对应的bean中去
      

  2.   

    [{"id":1001,"email":"[email protected]","name":"Tony","gender":"male"},{"id":1002,"email":"[email protected]","name":"Jack","gender":"male"},{"id":1003,"email":"[email protected]","name":"Marry","gender":"female"},{"id":1004,"email":"[email protected]","name":"Linda","gender":"female"}]
     JSONArray array = new JSONArray(body);
            for(int i=0; i<array.length(); i++){
             JSONObject obj = array.getJSONObject(i);
             sb.append("id:").append(obj.getInt("id")).append("\t");
             sb.append("name:").append(obj.getString("name")).append("\r\n");
             sb.append("gender:").append(obj.getString("gender")).append("\t");
             sb.append("email:").append(obj.getString("email")).append("\r\n");
             sb.append("----------------------\r\n");
            }
      

  3.   

    String content="{"user_info":{"province":"省",
    "city":"城市","name":"名字",
    "perid":"2009年12月01日至2009年12月31日"},
    }";JSONObject ob=new JSONObject(content);
    Object object=JSONObject.toBean(ob.getJSONObject("user_info"));