解析json

json所需的jar包

http://pan.baidu.com/s/1eRSM4Rg 密码:0u2o

通过http网址解析json

public class JsonUtil {
	
	/**
	 * 解析json数据
	 * @param url 网址
	 * @return json字符串
	 */
	public static String getJson(String url){
		URL jsonFileUrl = null;
		InputStream is = null;
		InputStreamReader isr =null;
		StringBuffer sb = new StringBuffer();
		BufferedReader br = null;
			try {
				jsonFileUrl = new URL(url);
				is = jsonFileUrl.openStream(); 
				isr = new InputStreamReader(is,"utf-8");
				br = new BufferedReader(isr);
				String temp = null;
				while((temp=br.readLine())!=null){
					sb.append(temp);
				}
			} catch (FileNotFoundException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}finally{
				if(br!=null){
					try {
						br.close();
					} catch (IOException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
				}
				if(isr!=null){
					try {
						br.close();
					} catch (IOException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
				}
				if(is!=null){
					try {
						br.close();
					} catch (IOException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
				}
			}
		
		return sb.toString();
	}
	@Test
	public void testJsonFile(){
		String jsonString = JsonUtil.getJson("http://api.meituan.com/mmdb/movie/v2/list/rt/order/coming.json?ci=1&limit=12&token=&__vhost"
				+ "=api.maoyan.com&utm_campaign=AmovieBmovieCD-1&movieBundleVersion=6801&utm_source=xiaomi&utm_medium=android&utm_term=6.8.0&utm_content=868030022327462&net=255&dModel=MI%205&uuid=0894DE03C76F6045D55977B6D4E32B7F3C6AAB02F9CEA042987B380EC5687C43&lat=40.100673&lng=116.378619&__skck=6a375bce8c66a0dc293860dfa83833ef&__skts=1463704714271&__skua=7e01cf8dd30a179800a7a93979b430b2&__skno=1a0b4a9b-44ec-42fc-b110-ead68bcc2824&__skcy=sXcDKbGi20CGXQPPZvhCU3%2FkzdE%3D");
		JSONObject json = JSONObject.fromObject(jsonString);
		JSONObject data = (JSONObject) json.get("data");
		JSONArray comming = data.getJSONArray("coming");
		List<Object> list = new ArrayList<Object>();
		int size = comming.size();
		for(int i = 0;i<size;i++){
			JSONObject jsonObject= (JSONObject) comming.get(i);
			//获取dur的值
			String dur = (String) jsonObject.getString("img");
			list.add(dur);
		}
		System.out.println(list.toString());
		
	}



  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值