java 测试处理json数据

来源:互联网 发布:罗技游戏鼠标推荐 知乎 编辑:程序博客网 时间:2024/06/06 18:02
String a="{'plan':[{'PLAN_START_DATE':'1','ID':'','PLAN_END_DATE':'2012-04-30'},{'PLAN_START_DATE':'1','ID':'b2','PLAN_END_DATE':'2013-05-31'}]}";
  JSONObject object =JSONObject.fromObject(a);
  JSONArray  array=object.getJSONArray("plan");
  String tID="";
  String tSdate="";
  String tEdate="";
    Map outParameters=new HashMap();
  for (int i = 0; i < array.size(); i++) {
      JSONObject getData=array.getJSONObject(i);
      tID=tID+getData.get("ID").toString()+",";//拼接字符串ID
      tSdate=tSdate+getData.get("PLAN_START_DATE").toString()+",";
      tEdate=tEdate+getData.get("PLAN_END_DATE").toString()+",";
  }
  Integer index1=tID.lastIndexOf(",");
  tID=tID.substring(0,index1);
  Integer index2=tSdate.lastIndexOf(",");
  tSdate=tSdate.substring(0,index2);
  Integer index3=tEdate.lastIndexOf(",");
  tEdate=tEdate.substring(0,index3);
  System.out.println(tID);
  System.out.println(tSdate);
  System.out.println(tEdate);
原创粉丝点击