通过URL获取后台的json

1. json包下载地址 http://download.csdn.net/detail/wsk1103/9685504
2. 后台使用json时,需要导入json相关的包,并且后台导入的json为import net.sf.json.*;
3. 将list转化为jsonarray的方法(该方法返回的是数组的形式)
List list=new ArrayList();
JSONArray ja=new JSONArray();
ja=JSONArray.fromObject(list);
然后将该ja输出到就可以了
4. 如果想返回的形式是对象的形式,使用的是JSONObject,方法是一样的
5. 将json输出方法
byte[] jsonBytes = null;
jsonBytes = jsonArray.toString().getBytes("utf-8");
response.setContentLength(jsonBytes.length);
response.getOutputStream().write(jsonBytes);
response.getOutputStream().flush();
response.getOutputStream().close();
输出的就是json格式的值
http://download.csdn.net/detail/wsk1103/9685504

你可能感兴趣的:(问题解决方案)