<span>package test;
import utils.XUtils;
import com.alibaba.fastjson.JSON;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
public class Main {
public static void main(String[] args) {
// TODO Auto-generated method stub
String url="http://tingapi.ting.baidu.com/v1/restserver/ting?from=qianqian&version=2.1.0&method=baidu.ting.song.getInfos&format=json&songid=8059247&ts=1408284347323&e=JoN56kTXnnbEpd9MVczkYJCSx%2FE1mkLx%2BPMIkTcOEu4%3D&nw=2&ucf=1&res=1&qq-pf-to=pcqq.c2c";
XUtils.getXml(url,new XUtils.CallBack() {
public void response(byte[] bytes) {
try {
//System.out.println(new String(bytes));
//谷歌解析
TypeToken<Bean> token=new TypeToken<Bean>(){};
Gson gson=new Gson();
Bean bean=gson.fromJson(new String(bytes), token.getType());
System.out.println(bean);
//阿里巴巴的解析
//Bean t=JSON.parseObject(new String(bytes),Bean.class);
//System.out.println(t);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
});
}
}</span>
Tags:json java 数据解析 异步下载 java