怎么判断返回值的格式为json

 我来答
若以下回答无法解决问题,邀请你更新回答
匿名用户
2016-07-12
展开全部
例如: 
  Student st1 = new Student(1, "dg", 18, new Date());
  Student st2 = new Student(2, "dg", 18, new Date());
  Student st3 = new Student(3, "dg", 18, new Date());
  Student st4 = new Student(4, "dg", 18, new Date());
  Student st5 = new Student(5, "dg", 18, new Date());
  List li = new ArrayList();
  JSONObject JO1 = new JSONObject(st1);
  JSONObject JO2 = new JSONObject(st2);
  JSONObject JO3 = new JSONObject(st3);
  JSONObject JO4 = new JSONObject(st4);
  JSONObject JO5 = new JSONObject(st5);
  li.add(JO1);
  li.add(JO2);
  li.add(JO3);
  li.add(JO4);
  li.add(JO5);
  JSONArray Ja = new JSONArray(li);
  Map ma = new HashMap();
  ma.put("Result", "OK");
  ma.put("Records", Ja);
  JSONObject js = new JSONObject(ma);
  out.print(js);

  返回结果:

  {"Result":"OK","Records":[{"recordDate":"Fri Dec 16 17:54:39 CST 2011","name":"dg","age":18,"personId":1},{"recordDate":"Fri Dec 16 17:54:39 CST 2011","name":"dg","age":18,"personId":2},{"recordDate":"Fri Dec 16 17:54:39 CST 2011","name":"dg","age":18,"personId":3},{"recordDate":"Fri Dec 16 17:54:39 CST 2011","name":"dg","age":18,"personId":4},{"recordDate":"Fri Dec 16 17:54:39 CST 2011","name":"dg","age":18,"personId":5}]}
本回答被网友采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 1条折叠回答
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式