GSON解析
来源:互联网 发布:比特鱼软件下载 编辑:程序博客网 时间:2024/05/20 23:05
public void getDataHppt(){
getHppt("http://v.juhe.cn/movie/index?key=c2cbcf239e03beac33a32abd8de153d1&title=电影");
}
public void getHppt(String url){
new AsyncTask<String,Void,String>(){
@Override
protected void onPostExecute(String s) {
super.onPostExecute(s);
if(s==null){
return;
}
Gson gson=new Gson();
BeanDemo beanDemo = gson.fromJson(s, BeanDemo.class);
final List<BeanDemo.ResultBean> resultlist = beanDemo.getResult();
MyAdapterDemo adapter=new MyAdapterDemo(getActivity(),resultlist);
xlv.setAdapter(adapter);
}
@Override
protected String doInBackground(String... params) {
try {
URL url=new URL(params[0]);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("GET");
connection.setConnectTimeout(5000);
connection.setReadTimeout(5000);
int code = connection.getResponseCode();
if(code==200) {
InputStream is = connection.getInputStream();
return StringDemo.getJson(is);
}
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
public static String getJson(InputStream is){
try {
ByteArrayOutputStream baos=new ByteArrayOutputStream();
byte[]buff=new byte[1024];
int len=0;
while((len=is.read(buff))!=-1){
baos.write(buff,0,len);
}
baos.flush();
baos.close();
is.close();
return baos.toString();
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
getHppt("http://v.juhe.cn/movie/index?key=c2cbcf239e03beac33a32abd8de153d1&title=电影");
}
public void getHppt(String url){
new AsyncTask<String,Void,String>(){
@Override
protected void onPostExecute(String s) {
super.onPostExecute(s);
if(s==null){
return;
}
Gson gson=new Gson();
BeanDemo beanDemo = gson.fromJson(s, BeanDemo.class);
final List<BeanDemo.ResultBean> resultlist = beanDemo.getResult();
MyAdapterDemo adapter=new MyAdapterDemo(getActivity(),resultlist);
xlv.setAdapter(adapter);
}
@Override
protected String doInBackground(String... params) {
try {
URL url=new URL(params[0]);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("GET");
connection.setConnectTimeout(5000);
connection.setReadTimeout(5000);
int code = connection.getResponseCode();
if(code==200) {
InputStream is = connection.getInputStream();
return StringDemo.getJson(is);
}
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
}.execute(url);
public class StringDemo {
public static String getJson(InputStream is){
try {
ByteArrayOutputStream baos=new ByteArrayOutputStream();
byte[]buff=new byte[1024];
int len=0;
while((len=is.read(buff))!=-1){
baos.write(buff,0,len);
}
baos.flush();
baos.close();
is.close();
return baos.toString();
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
阅读全文
0 0
- Gson解析
- GSON解析
- Gson解析
- Gson解析
- Gson解析
- Gson解析
- GSON解析
- Gson解析
- Gson解析
- Gson解析
- Gson解析
- Gson 解析
- gson解析
- Gson解析
- gson解析
- Gson解析
- GSON解析
- Gson解析
- 2.6 军事原则总结
- 比较单张扑克牌的大小的小技巧
- PWA(Progressive Web App)初探总结
- 第三章 管理学通论——3.1&nbsp…
- 3.2 系统分析之正反馈
- GSON解析
- 3.2.2 彼得•圣吉的正反馈
- 巧用阿里云共享带宽包,为企业降低50%带宽成本
- 3.2.3 比尔•盖茨的正反馈
- 3.2.4 巴菲特的滚雪球
- 3.2.4.2 巴菲特,索罗斯和西蒙斯
- 3.2.5 乔布斯的平台
- 3.2.6 索罗斯的反身理论
- odoo xml解析错误