StringBuffer stringBuffer=new StringBuffer();
  List list=new ArrayList();
  Map<String, String> testmap = new HashMap<String, String>();
  testmap.put("status", "1");
  testmap.put("ticket_code", "11111");
  testmap.put("lotteryNo", "CMK");
  testmap.put("playTypeCode", "1");
  testmap.put("issue", "1");
  list.add(testmap);
  stringBuffer.append(testmap+",");
  testmap = new HashMap<String, String>();
  testmap.put("status", "2");
  testmap.put("ticket_code", "22222");
  testmap.put("lotteryNo", "CMK");
  testmap.put("playTypeCode", "1");
  testmap.put("issue", "2");
  list.add(testmap);
  Gson gson = new Gson();// 初始gson对象
  String json = gson.toJson(list);// 调用Gson的方法toJson把对象转换
  System.out.println(json);


     JsonParser jsonparer = new JsonParser();// 初始化解析json格式的对象
     JsonArray jsonName = jsonparer.parse(json).getAsJsonArray();
     for(int i=0;i<jsonName.size();i++){
        JsonElement jsonElement= jsonName.get(i);
        JsonObject jObject=jsonElement.getAsJsonObject();
        String str=jObject.get("ticket_code").getAsString();
        System.out.println(str);
     }

posted on 2012-07-18 17:17  清沁  阅读(424)  评论(0编辑  收藏  举报