用Xstream解析XML
2016-05-15 20:42
162 查看
url="http://www.oschina.net/action/api/news_list";
public class MyNews implements Serializable{
private String id;
private String title;
private String body;
private String commentCount;
private String author;
private String authorid;
private String pubDate;
private String url;
private MyNewstype newstype;
}
package com.fan.homework_2.bean;
import java.io.Serializable;
import java.util.List;
import com.thoughtworks.xstream.annotations.XStreamAlias;
import com.thoughtworks.xstream.annotations.XStreamImplicit;
@XStreamAlias("newslist")
public class Mynewslist implements Serializable{
@XStreamImplicit(itemFieldName="news")
private List<MyNews> news;
public List<MyNews> getNews() {
return news;
}
public void setNews(List<MyNews> news) {
this.news = news;
}
}
public class MyNewstype implements Serializable{
private String type;
private String attachment;
private String authoruid2;
private String eventurl;
}
import com.thoughtworks.xstream.annotations.XStreamAlias;
@XStreamAlias("oschina")
public class Good implements Serializable{
private String catalog;
private String newsCount;
private String pagesize;
public Mynewslist newslist;
}
//从网络上请求数据
private void getData() {
String url = "http://www.oschina.net/action/api/news_list?catalog=1&pageIndex="
+ pageIndex + "&pageSize=20";
HttpUtils httpUtils=new HttpUtils();
httpUtils.send(HttpMethod.GET, url, new RequestCallBack<String>() {
@Override
public void onFailure(HttpException arg0, String arg1) {
Log.d(TAG, "请求失败!");
}
@Override
public void onSuccess(ResponseInfo<String> arg0) {
XStream stream=new XStream();
stream.processAnnotations(Good.class);
Good good=(Good) stream.fromXML(arg0.result);
newsList = good.getNewslist().getNews();
allList.addAll(newsList);
myListAdapter.addrest(allList);
}
});
public class MyNews implements Serializable{
private String id;
private String title;
private String body;
private String commentCount;
private String author;
private String authorid;
private String pubDate;
private String url;
private MyNewstype newstype;
}
package com.fan.homework_2.bean;
import java.io.Serializable;
import java.util.List;
import com.thoughtworks.xstream.annotations.XStreamAlias;
import com.thoughtworks.xstream.annotations.XStreamImplicit;
@XStreamAlias("newslist")
public class Mynewslist implements Serializable{
@XStreamImplicit(itemFieldName="news")
private List<MyNews> news;
public List<MyNews> getNews() {
return news;
}
public void setNews(List<MyNews> news) {
this.news = news;
}
}
public class MyNewstype implements Serializable{
private String type;
private String attachment;
private String authoruid2;
private String eventurl;
}
import com.thoughtworks.xstream.annotations.XStreamAlias;
@XStreamAlias("oschina")
public class Good implements Serializable{
private String catalog;
private String newsCount;
private String pagesize;
public Mynewslist newslist;
}
//从网络上请求数据
private void getData() {
String url = "http://www.oschina.net/action/api/news_list?catalog=1&pageIndex="
+ pageIndex + "&pageSize=20";
HttpUtils httpUtils=new HttpUtils();
httpUtils.send(HttpMethod.GET, url, new RequestCallBack<String>() {
@Override
public void onFailure(HttpException arg0, String arg1) {
Log.d(TAG, "请求失败!");
}
@Override
public void onSuccess(ResponseInfo<String> arg0) {
XStream stream=new XStream();
stream.processAnnotations(Good.class);
Good good=(Good) stream.fromXML(arg0.result);
newsList = good.getNewslist().getNews();
allList.addAll(newsList);
myListAdapter.addrest(allList);
}
});
相关文章推荐
- LintCode : Unique Paths
- Azure ServiceBus 架构简介
- 引用与指针
- HDU 1498 50 years, 50 colors(最小顶点覆盖)
- Fragment事务及Fragment实现选项卡功能
- 顺序表应用6:有序顺序表查询
- 从头认识多线程-2.19 synchronized同步方法的无限等待与解决方法
- 深度学习模型之各种caffe版本(Linux和windows)的网址
- 团队博客1
- Nginx安装与优化
- Java基本数据类型和运算符
- C++虚函数表解析
- C++ 函数重载
- 2016百度之星
- mysql字符集修改
- 基于JDBC层数据权限是如何设计的
- 团体程序设计天梯赛-模拟赛(2016年)
- 戒烟20分钟-15年
- 百度前端技术学院task35源代码——听指令的小方块3
- 系统架构设计——设计模式之代理模式(一)