网络请求(listview json解析 数据库存储)【周五01.08】

adapter 包

MyBaseAdapter类

 1 package com.cp.adapter;
 2
 3 import java.util.List;
 4
 5 import android.content.Context;
 6 import android.view.LayoutInflater;
 7 import android.view.View;
 8 import android.view.ViewGroup;
 9 import android.widget.BaseAdapter;
10 import android.widget.ImageView;
11 import android.widget.TextView;
12
13 import com.cp.day07zuoye.R;
14 import com.cp.vo.NewsList;
15 import com.lidroid.xutils.BitmapUtils;
16
17 public class MyBaseAdapter extends BaseAdapter{
18     private Context con;
19     private List<NewsList> list;
20     //创建构造器获取上下文菜单和集合
21     public MyBaseAdapter(Context con,List<NewsList> list){
22         this.con = con;
23         this.list = list;
24     }
25     @Override
26     public int getCount() {
27         return list.size();
28     }
29
30     @Override
31     public Object getItem(int position) {
32         return null;
33     }
34
35     @Override
36     public long getItemId(int position) {
37         return 0;
38     }
39
40     @Override
41     public View getView(int position, View convertView, ViewGroup parent) {
42         ViewHolder holder = null;
43         if(convertView == null){
44             holder = new ViewHolder();
45             convertView = LayoutInflater.from(con).inflate(R.layout.list_item, null);
46             holder.image = (ImageView) convertView.findViewById(R.id.image);
47             holder.title = (TextView) convertView.findViewById(R.id.title);
48             holder.intro = (TextView) convertView.findViewById(R.id.intro);
49             convertView.setTag(holder);
50         }else{
51             holder = (ViewHolder) convertView.getTag();
52         }
53         NewsList news = list.get(position);
54         //利用BitmapUtils类加载图片到ImageView上
55         BitmapUtils bit = new BitmapUtils(con);
56         bit.display(holder.image, news.getPic());
57         holder.title.setText(news.getTitle());
58         holder.intro.setText(news.getIntro());
59         return convertView;
60     }
61     //内部持有类
62     class ViewHolder{
63         ImageView image;
64         TextView title;
65         TextView intro;
66     }
67 }
MyCollBaseAdapter类
 1 package com.cp.adapter;
 2
 3 import java.util.List;
 4
 5 import android.content.Context;
 6 import android.view.LayoutInflater;
 7 import android.view.View;
 8 import android.view.ViewGroup;
 9 import android.widget.BaseAdapter;
10 import android.widget.ImageView;
11 import android.widget.TextView;
12
13 import com.cp.day07zuoye.R;
14 import com.cp.vo.Collection;
15 import com.cp.vo.NewsList;
16 import com.lidroid.xutils.BitmapUtils;
17
18 public class MyCollBaseAdapter extends BaseAdapter{
19     private Context con;
20     private List<Collection> list;
21
22     public MyCollBaseAdapter(Context con,List<Collection> list){
23         this.con = con;
24         this.list = list;
25     }
26     @Override
27     public int getCount() {
28         return list.size();
29     }
30
31     @Override
32     public Object getItem(int position) {
33         return null;
34     }
35
36     @Override
37     public long getItemId(int position) {
38         return 0;
39     }
40
41     @Override
42     public View getView(int position, View convertView, ViewGroup parent) {
43         ViewHolder holder = null;
44         if(convertView == null){
45             holder = new ViewHolder();
46             convertView = LayoutInflater.from(con).inflate(R.layout.list_item, null);
47             holder.image = (ImageView) convertView.findViewById(R.id.image);
48             holder.title = (TextView) convertView.findViewById(R.id.title);
49             holder.intro = (TextView) convertView.findViewById(R.id.intro);
50             convertView.setTag(holder);
51         }else{
52             holder = (ViewHolder) convertView.getTag();
53         }
54         Collection news = list.get(position);
55         BitmapUtils bit = new BitmapUtils(con);
56         bit.display(holder.image, news.getPic());
57         holder.title.setText(news.getTitle());
58         holder.intro.setText(news.getIntro());
59         return convertView;
60     }
61     class ViewHolder{
62         ImageView image;
63         TextView title;
64         TextView intro;
65     }
66 }
day07zuoye包
MainActivity
  1 package com.cp.day07zuoye;
  2
  3 import java.io.BufferedReader;
  4 import java.io.IOException;
  5 import java.io.InputStreamReader;
  6 import java.net.HttpURLConnection;
  7 import java.net.MalformedURLException;
  8 import java.net.URL;
  9 import java.util.List;
 10
 11 import android.app.Activity;
 12 import android.content.Intent;
 13 import android.os.Bundle;
 14 import android.os.Handler;
 15 import android.os.Message;
 16 import android.view.Menu;
 17 import android.view.View;
 18 import android.widget.AdapterView;
 19 import android.widget.AdapterView.OnItemClickListener;
 20 import android.widget.ListView;
 21
 22 import com.cp.adapter.MyBaseAdapter;
 23 import com.cp.vo.Collection;
 24 import com.cp.vo.MyData;
 25 import com.cp.vo.NewsList;
 26 import com.google.gson.Gson;
 27 import com.lidroid.xutils.DbUtils;
 28 import com.lidroid.xutils.exception.DbException;
 29
 30 public class MainActivity extends Activity {
 31     //新闻地址
 32     public static final String NEWSURL = "http://api.sina.cn/sinago/list.json?channel=hdpic_story&adid=4ad30dabe134695c3d7c3a65977d7e72&from=6042095012&chwm=12050_0001&imei=867064013906290&uid=802909da86d9f5fc&p=1";
 33     private List<NewsList> news;
 34     Handler handler = new Handler(){
 35
 36         public void handleMessage(android.os.Message msg) {
 37             MyData mydata = parseJson((String)msg.obj);
 38             news = mydata.getData().getList();
 39             insertData(news);
 40             MyBaseAdapter adapter = new MyBaseAdapter(MainActivity.this, news);
 41             newsList.setAdapter(adapter);
 42         };
 43     };
 44     private ListView newsList;
 45     @Override
 46     protected void onCreate(Bundle savedInstanceState) {
 47         super.onCreate(savedInstanceState);
 48         setContentView(R.layout.activity_main);
 49         init();
 50
 51     }
 52     private void init() {
 53         //找到一个控件
 54         newsList = (ListView)findViewById(R.id.newsList);
 55         //在子线程中请求网络
 56         new Thread(){
 57             public void run() {
 58                 String json = getJsonFromHttp(NEWSURL);
 59                 Message msg = new Message();
 60                 msg.obj = json;
 61                 handler.sendMessage(msg);
 62             };
 63         }.start();
 64         //listView的条目监听
 65         newsList.setOnItemClickListener(new OnItemClickListener() {
 66
 67             @Override
 68             public void onItemClick(AdapterView<?> arg0, View view, int position,
 69                     long arg3) {
 70                 //获取条目所对应的newslist对象
 71                 NewsList n = news.get(position);
 72                 //通过Bundle传递newslist对象
 73                 Intent intent = new Intent(MainActivity.this,NewsInformation.class);
 74                 Bundle b = new Bundle();
 75                 b.putSerializable("news", n);
 76                 intent.putExtras(b);
 77                 startActivity(intent);
 78             }
 79
 80         });
 81
 82     }
 83
 84     //请求json数据
 85     public String getJsonFromHttp(String uri){
 86         URL url;
 87         StringBuffer sb = new StringBuffer();
 88         try {
 89             url = new URL(uri);
 90             HttpURLConnection httpUrl = (HttpURLConnection) url.openConnection();
 91             httpUrl.setRequestMethod("GET");
 92             httpUrl.setConnectTimeout(5000);
 93             httpUrl.setReadTimeout(5000);
 94             if(httpUrl.getResponseCode() == 200){
 95                 BufferedReader br = new BufferedReader(new InputStreamReader(httpUrl.getInputStream(),"utf-8"));
 96                 String str = "";
 97                 while((str = br.readLine()) != null){
 98                     sb.append(str);
 99                 }
100             }
101         } catch (MalformedURLException e) {
102             e.printStackTrace();
103         } catch (IOException e) {
104             e.printStackTrace();
105         }
106         return sb.toString();
107     }
108
109     //解析json数据
110     public MyData parseJson(String json){
111         Gson g = new Gson();
112         MyData mydata = g.fromJson(json, MyData.class);
113         return mydata;
114     }
115
116
117     //创建并添加数据到数据库的方法
118     public void insertData(List<NewsList> list){
119         DbUtils db = DbUtils.create(MainActivity.this, "newsData");
120         try {
121             db.createTableIfNotExist(NewsList.class);
122             db.createTableIfNotExist(Collection.class);
123             db.saveAll(list);
124         } catch (DbException e) {
125             e.printStackTrace();
126         }
127     }
128
129     @Override
130     protected void onDestroy() {
131         super.onDestroy();
132         //Activity销毁时将newslist表中的数据清空
133         DbUtils db = DbUtils.create(MainActivity.this, "newsData");
134         try {
135             db.deleteAll(NewsList.class);
136         } catch (DbException e) {
137             e.printStackTrace();
138         }
139     }
140
141
142
143
144
145
146     @Override
147     public boolean onCreateOptionsMenu(Menu menu) {
148         // Inflate the menu; this adds items to the action bar if it is present.
149         getMenuInflater().inflate(R.menu.activity_main, menu);
150         return true;
151     }
152
153 }
MyCollection
 1 package com.cp.day07zuoye;
 2
 3 import java.util.List;
 4
 5 import com.cp.adapter.MyBaseAdapter;
 6 import com.cp.adapter.MyCollBaseAdapter;
 7 import com.cp.vo.Collection;
 8 import com.lidroid.xutils.DbUtils;
 9 import com.lidroid.xutils.exception.DbException;
10
11 import android.app.Activity;
12 import android.os.Bundle;
13 import android.view.Menu;
14 import android.widget.ListView;
15
16 public class MyCollection extends Activity {
17
18     @Override
19     protected void onCreate(Bundle savedInstanceState) {
20         super.onCreate(savedInstanceState);
21         setContentView(R.layout.activity_my_collection);
22         init();
23     }
24
25     private void init() {
26         ListView listView = (ListView)findViewById(R.id.myListView);
27         //创建适配器
28         MyCollBaseAdapter adapter = new MyCollBaseAdapter(MyCollection.this, findAllData());
29         //加载适配器
30         listView.setAdapter(adapter);
31     }
32
33     //查询收藏表全查
34     public List<Collection> findAllData(){
35         DbUtils db = DbUtils.create(MyCollection.this, "newsData");
36         List<Collection> list = null;
37         try {
38             list =  db.findAll(Collection.class);
39         } catch (DbException e) {
40             // TODO Auto-generated catch block
41             e.printStackTrace();
42         }
43         return list;
44     }
45
46 }
NewsInformation
  1 package com.cp.day07zuoye;
  2
  3 import java.lang.reflect.InvocationTargetException;
  4 import java.util.List;
  5
  6 import org.apache.commons.beanutils.BeanUtils;
  7
  8 import android.app.Activity;
  9 import android.content.Intent;
 10 import android.database.Cursor;
 11 import android.database.sqlite.SQLiteDatabase;
 12 import android.os.Bundle;
 13 import android.view.Menu;
 14 import android.view.View;
 15 import android.view.View.OnClickListener;
 16 import android.widget.Button;
 17 import android.widget.ImageView;
 18 import android.widget.TextView;
 19 import android.widget.Toast;
 20
 21 import com.cp.helper.MyHelper;
 22 import com.cp.vo.Collection;
 23 import com.cp.vo.NewsList;
 24 import com.lidroid.xutils.BitmapUtils;
 25 import com.lidroid.xutils.DbUtils;
 26 import com.lidroid.xutils.db.sqlite.Selector;
 27 import com.lidroid.xutils.exception.DbException;
 28
 29 public class NewsInformation extends Activity implements OnClickListener {
 30
 31     private NewsList newslist;
 32
 33     @Override
 34     protected void onCreate(Bundle savedInstanceState) {
 35         super.onCreate(savedInstanceState);
 36         setContentView(R.layout.activity_news_information);
 37         init();
 38     }
 39     private void init() {
 40         //获取控件
 41         ImageView image = (ImageView)findViewById(R.id.info_image);
 42         TextView infoTitle = (TextView)findViewById(R.id.info_title);
 43         TextView infoLongTitle = (TextView)findViewById(R.id.info_longtitle);
 44         TextView infoIntro = (TextView)findViewById(R.id.info_intro);
 45         Button collection = (Button)findViewById(R.id.collection);
 46         Button mine = (Button)findViewById(R.id.mine);
 47         Button back = (Button)findViewById(R.id.back);
 48         //注册监听
 49         collection.setOnClickListener(this);
 50         mine.setOnClickListener(this);
 51         back.setOnClickListener(this);
 52         //得到Intent
 53         Intent intent = getIntent();
 54         //得到Bundle
 55         Bundle b = intent.getExtras();
 56         //得到传递过来的对象
 57         newslist = (NewsList) b.getSerializable("news");
 58         //给各个控件赋值
 59         BitmapUtils bit = new BitmapUtils(NewsInformation.this);
 60         bit.display(image, newslist.getKpic());
 61         infoTitle.setText(newslist.getTitle());
 62         infoLongTitle.setText(newslist.getLong_title());
 63         infoIntro.setText(newslist.getIntro());
 64
 65     }
 66     //按钮监听
 67     @Override
 68     public void onClick(View v) {
 69         switch(v.getId()){
 70         case R.id.collection:
 71             //点击收藏保存到收藏表中
 72             DbUtils db = DbUtils.create(NewsInformation.this, "newsData");
 73             try {
 74                 Collection  c = new Collection();
 75                 //commons-beanutils-1.8.3.jar
 76                 //BeanUtils.copyProperties(c,newslist);
 77                 c.setPic(newslist.getPic());
 78                 c.setTitle(newslist.getTitle());
 79                 c.setIntro(newslist.getIntro());
 80                 c.setId(newslist.getId());
 81                 //如果收藏过就吐司提示不再收藏
 82                 if(findData(c.getId())){
 83                     Toast.makeText(NewsInformation.this, "已经收藏过", 0).show();
 84                     return;
 85                 }
 86                 db.save(c);
 87                 Toast.makeText(NewsInformation.this, "收藏成功", 0).show();
 88             } catch (DbException e) {
 89                 e.printStackTrace();
 90             }
 91             break;
 92         case R.id.mine:
 93             //跳转到我的收藏界面
 94             Intent intent = new Intent(NewsInformation.this,MyCollection.class);
 95             startActivity(intent);
 96             break;
 97         case R.id.back:
 98             //返回
 99             finish();
100             break;
101         }
102     }
103
104
105     //根据id查询数据库的方法
106     public boolean findData(String id){
107         boolean b = false;
108         DbUtils db = DbUtils.create(NewsInformation.this, "newsData");
109         MyHelper helper = new MyHelper(NewsInformation.this, "newsData", null, 1);
110         SQLiteDatabase sdb = helper.getReadableDatabase();
111
112         try {
113             //Cursor c = (Cursor) db.findAll(Selector.from(Collection.class).where("id", "=", id));
114             Cursor c = sdb.query("com_cp_vo_Collection", null, "id = ?", new String[]{id}, null, null, null);
115             b = c.moveToNext();
116         } catch (Exception e) {
117             e.printStackTrace();
118         }finally{
119             sdb.close();
120         }
121         return b;
122     }
123
124
125
126
127     @Override
128     public boolean onCreateOptionsMenu(Menu menu) {
129         // Inflate the menu; this adds items to the action bar if it is present.
130         getMenuInflater().inflate(R.menu.activity_news_information, menu);
131         return true;
132     }
133
134 }
helper包
MyHelper类 1 package com.cp.helper;
 2
 3 import android.content.Context;
 4 import android.database.sqlite.SQLiteDatabase;
 5 import android.database.sqlite.SQLiteDatabase.CursorFactory;
 6 import android.database.sqlite.SQLiteOpenHelper;
 7
 8 public class MyHelper extends SQLiteOpenHelper{
 9
10     public MyHelper(Context context, String name, CursorFactory factory,
11             int version) {
12         super(context, name, factory, version);
13         // TODO Auto-generated constructor stub
14     }
15
16     @Override
17     public void onCreate(SQLiteDatabase db) {
18
19     }
20
21     @Override
22     public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
23         // TODO Auto-generated method stub
24
25     }
26
27 }
vo
Collection
  1 package com.cp.vo;
  2
  3 import com.lidroid.xutils.db.annotation.Id;
  4 //收藏表类
  5 public class Collection {
  6     @Id
  7     private int n_id;
  8     private int articlePubDate;
  9     private String bpic;
 10     private String category;
 11     private int comment;
 12     private CommentCountInfo comment_count_info;
 13     private String comments;
 14     private String feedShowStyle;
 15     private String id;
 16     private String intro;
 17     private String kpic;
 18     private String link;
 19     private String long_title;
 20     private String pic;
 21     private MyPics pics;
 22     private long pubDate;
 23     private String source;
 24     private String title;
 25     public int getArticlePubDate() {
 26         return articlePubDate;
 27     }
 28     public void setArticlePubDate(int articlePubDate) {
 29         this.articlePubDate = articlePubDate;
 30     }
 31     public String getBpic() {
 32         return bpic;
 33     }
 34     public void setBpic(String bpic) {
 35         this.bpic = bpic;
 36     }
 37     public String getCategory() {
 38         return category;
 39     }
 40     public void setCategory(String category) {
 41         this.category = category;
 42     }
 43     public int getComment() {
 44         return comment;
 45     }
 46     public void setComment(int comment) {
 47         this.comment = comment;
 48     }
 49     public CommentCountInfo getComment_count_info() {
 50         return comment_count_info;
 51     }
 52     public void setComment_count_info(CommentCountInfo comment_count_info) {
 53         this.comment_count_info = comment_count_info;
 54     }
 55     public String getComments() {
 56         return comments;
 57     }
 58     public void setComments(String comments) {
 59         this.comments = comments;
 60     }
 61     public String getFeedShowStyle() {
 62         return feedShowStyle;
 63     }
 64     public void setFeedShowStyle(String feedShowStyle) {
 65         this.feedShowStyle = feedShowStyle;
 66     }
 67     public String getId() {
 68         return id;
 69     }
 70     public void setId(String id) {
 71         this.id = id;
 72     }
 73     public String getIntro() {
 74         return intro;
 75     }
 76     public void setIntro(String intro) {
 77         this.intro = intro;
 78     }
 79     public String getKpic() {
 80         return kpic;
 81     }
 82     public void setKpic(String kpic) {
 83         this.kpic = kpic;
 84     }
 85     public String getLink() {
 86         return link;
 87     }
 88     public void setLink(String link) {
 89         this.link = link;
 90     }
 91     public String getLong_title() {
 92         return long_title;
 93     }
 94     public void setLong_title(String long_title) {
 95         this.long_title = long_title;
 96     }
 97     public String getPic() {
 98         return pic;
 99     }
100     public void setPic(String pic) {
101         this.pic = pic;
102     }
103     public MyPics getPics() {
104         return pics;
105     }
106     public void setPics(MyPics pics) {
107         this.pics = pics;
108     }
109     public long getPubDate() {
110         return pubDate;
111     }
112     public void setPubDate(long pubDate) {
113         this.pubDate = pubDate;
114     }
115     public String getSource() {
116         return source;
117     }
118     public void setSource(String source) {
119         this.source = source;
120     }
121     public String getTitle() {
122         return title;
123     }
124     public void setTitle(String title) {
125         this.title = title;
126     }
127 }
CommentCountInfo
 1 package com.cp.vo;
 2
 3 import java.io.Serializable;
 4
 5 public class CommentCountInfo implements Serializable {
 6     private int comment_status;
 7     private int praise;
 8     private int dispraise;
 9     private int qreply;
10     private int show;
11     private int total;
12     public int getComment_status() {
13         return comment_status;
14     }
15     public void setComment_status(int comment_status) {
16         this.comment_status = comment_status;
17     }
18     public int getPraise() {
19         return praise;
20     }
21     public void setPraise(int praise) {
22         this.praise = praise;
23     }
24     public int getDispraise() {
25         return dispraise;
26     }
27     public void setDispraise(int dispraise) {
28         this.dispraise = dispraise;
29     }
30     public int getQreply() {
31         return qreply;
32     }
33     public void setQreply(int qreply) {
34         this.qreply = qreply;
35     }
36     public int getShow() {
37         return show;
38     }
39     public void setShow(int show) {
40         this.show = show;
41     }
42     public int getTotal() {
43         return total;
44     }
45     public void setTotal(int total) {
46         this.total = total;
47     }
48     @Override
49     public String toString() {
50         return "CommentCountInfo [comment_status=" + comment_status
51                 + ", praise=" + praise + ", dispraise=" + dispraise
52                 + ", qreply=" + qreply + ", show=" + show + ", total=" + total
53                 + "]";
54     }
55
56 }
MyContent
 1 package com.cp.vo;
 2
 3 import java.util.List;
 4
 5 public class MyContent {
 6     private String is_intro;
 7     private List<NewsList> list;
 8     public List<NewsList> getList() {
 9         return list;
10     }
11     public void setList(List<NewsList> list) {
12         this.list = list;
13     }
14     public String getIs_intro() {
15         return is_intro;
16     }
17     public void setIs_intro(String is_intro) {
18         this.is_intro = is_intro;
19     }
20     @Override
21     public String toString() {
22         return "MyContent [is_intro=" + is_intro + ", list=" + list + "]";
23     }
24
25 }
MyData
 1 package com.cp.vo;
 2
 3 public class MyData {
 4     private MyContent data;
 5     private int status;
 6     public MyContent getData() {
 7         return data;
 8     }
 9     public void setData(MyContent data) {
10         this.data = data;
11     }
12     public int getStatus() {
13         return status;
14     }
15     public void setStatus(int status) {
16         this.status = status;
17     }
18     @Override
19     public String toString() {
20         return "MyData [data=" + data + ", status=" + status + "]";
21     }
22
23
24 }
MyPics
 1 package com.cp.vo;
 2
 3 import java.io.Serializable;
 4 import java.util.List;
 5
 6 public class MyPics implements Serializable{
 7     private List<Pics> list;
 8     private int picTemplate;
 9     private int total;
10     public List<Pics> getList() {
11         return list;
12     }
13     public void setList(List<Pics> list) {
14         this.list = list;
15     }
16     public int getPicTemplate() {
17         return picTemplate;
18     }
19     public void setPicTemplate(int picTemplate) {
20         this.picTemplate = picTemplate;
21     }
22     public int getTotal() {
23         return total;
24     }
25     public void setTotal(int total) {
26         this.total = total;
27     }
28     @Override
29     public String toString() {
30         return "MyPics [list=" + list + ", picTemplate=" + picTemplate
31                 + ", total=" + total + "]";
32     }
33
34 }
NewsList
  1 package com.cp.vo;
  2
  3 import java.io.Serializable;
  4
  5 import com.lidroid.xutils.db.annotation.Id;
  6
  7 public class NewsList implements Serializable {
  8     @Id
  9     private int n_id;
 10     private int articlePubDate;
 11     private String bpic;
 12     private String category;
 13     private int comment;
 14     private CommentCountInfo comment_count_info;
 15     private String comments;
 16     private String feedShowStyle;
 17     private String id;
 18     private String intro;
 19     private String kpic;
 20     private String link;
 21     private String long_title;
 22     private String pic;
 23     private MyPics pics;
 24     private long pubDate;
 25     private String source;
 26     private String title;
 27     public int getArticlePubDate() {
 28         return articlePubDate;
 29     }
 30     public void setArticlePubDate(int articlePubDate) {
 31         this.articlePubDate = articlePubDate;
 32     }
 33     public String getBpic() {
 34         return bpic;
 35     }
 36     public void setBpic(String bpic) {
 37         this.bpic = bpic;
 38     }
 39     public String getCategory() {
 40         return category;
 41     }
 42     public void setCategory(String category) {
 43         this.category = category;
 44     }
 45     public int getComment() {
 46         return comment;
 47     }
 48     public void setComment(int comment) {
 49         this.comment = comment;
 50     }
 51     public CommentCountInfo getComment_count_info() {
 52         return comment_count_info;
 53     }
 54     public void setComment_count_info(CommentCountInfo comment_count_info) {
 55         this.comment_count_info = comment_count_info;
 56     }
 57     public String getComments() {
 58         return comments;
 59     }
 60     public void setComments(String comments) {
 61         this.comments = comments;
 62     }
 63     public String getFeedShowStyle() {
 64         return feedShowStyle;
 65     }
 66     public void setFeedShowStyle(String feedShowStyle) {
 67         this.feedShowStyle = feedShowStyle;
 68     }
 69     public String getId() {
 70         return id;
 71     }
 72     public void setId(String id) {
 73         this.id = id;
 74     }
 75     public String getIntro() {
 76         return intro;
 77     }
 78     public void setIntro(String intro) {
 79         this.intro = intro;
 80     }
 81     public String getKpic() {
 82         return kpic;
 83     }
 84     public void setKpic(String kpic) {
 85         this.kpic = kpic;
 86     }
 87     public String getLink() {
 88         return link;
 89     }
 90     public void setLink(String link) {
 91         this.link = link;
 92     }
 93     public String getLong_title() {
 94         return long_title;
 95     }
 96     public void setLong_title(String long_title) {
 97         this.long_title = long_title;
 98     }
 99     public String getPic() {
100         return pic;
101     }
102     public void setPic(String pic) {
103         this.pic = pic;
104     }
105     public MyPics getPics() {
106         return pics;
107     }
108     public void setPics(MyPics pics) {
109         this.pics = pics;
110     }
111     public long getPubDate() {
112         return pubDate;
113     }
114     public void setPubDate(long pubDate) {
115         this.pubDate = pubDate;
116     }
117     public String getSource() {
118         return source;
119     }
120     public void setSource(String source) {
121         this.source = source;
122     }
123     public String getTitle() {
124         return title;
125     }
126     public void setTitle(String title) {
127         this.title = title;
128     }
129
130 }
Pics
 1 package com.cp.vo;
 2
 3 import java.io.Serializable;
 4
 5 public class Pics implements Serializable {
 6     private String alt;
 7     private String kpic;
 8     private String pic;
 9     public String getAlt() {
10         return alt;
11     }
12     public void setAlt(String alt) {
13         this.alt = alt;
14     }
15     public String getKpic() {
16         return kpic;
17     }
18     public void setKpic(String kpic) {
19         this.kpic = kpic;
20     }
21     public String getPic() {
22         return pic;
23     }
24     public void setPic(String pic) {
25         this.pic = pic;
26     }
27     @Override
28     public String toString() {
29         return "Pics [alt=" + alt + ", kpic=" + kpic + ", pic=" + pic + "]";
30     }
31
32
33 }
时间: 2024-12-20 13:09:15

网络请求(listview json解析 数据库存储)【周五01.08】的相关文章

Flutter - 网络请求与 json 解析

Flutter网络请求与JSON解析 Flutter网络请求与JSON解析 网络请求项目中用了两种,一个是 dart 自己的 dart:io, 另外一个是 dio 这个库. json 解析则用的是 dart:convert. 发起 HTTP 请求 首先我们需要先导入 http 的支持包,然后创建 httpClient. import 'dart:io'; var httpClient = new HttpClient(); HttpClient 支持常见的 get.post.put.delete

iOS 自己封装的网络请求,json解析的类

基本上所有的APP都会涉及网络这块,不管是用AFNetWorking还是自己写的http请求,整个网络框架的搭建很重要. 楼主封装的网络请求类,包括自己写的http请求和AFNetWorking的请求,代码简单,主要是框架搭建.简单来说,就是一个请求类,一个解析类,还有若干数据类. 以下代码以公开的天气查询api为例: 1.网络请求类 我把常用的网络请求方法都封装好了,你只需要写自己的接口,传递apiName,params等参数就可以. #pragma mark ios请求方式 //ios自带的

C#网络请求与JSON解析

最新学校的海康摄像头集控平台(网页端)不能在win10里登录,我寻思着拿海康的c# demo直接改. 首先得解决权限问题,每个教师任教不同年级,只能看到自己所在年级的设备,涉及到登录,在此记录一下C#中网络请求和数据处理的一些内容.大致流程为: 客户端发起登录请求: 服务端验证账号密码 返回json字符串,包含用户信息.平台配置等信息 客户端解析并初始化 一.发起GET请求 private string HttpGet(string api) { string serviceAddress =

网络请求之JSON解析

<一>JSON的基本知识 什么是JSON:JSON的全称是JavaScript Object Notation(JavaScript对象符号),是目前使用最广泛的数据交换格式,具有跨平台.跨语言的优势,而且对照XML,JSON作为数据传输格式时,数据传输量更小,JSON数据格式既适合人来进行读写,又适合计算机本身解析和合成 JSON的数据结构: 由key-value对组成的数据结构,这种数据结构在不同的语言中有不同的实现,例如:在JavaScript中是一个对象,在Objective-C中是一

android中网络请求数据,解析并添加到Listview中

今天我实现了网络请求数据,解析并将数据添加到Listview中.上个星期我有提到说要实现点击Listview中item实现不同的功能,还是没头绪.如有幸被阅读,希望指教一下.我用的是hTTPClient的post方法请求的数据.在实现请求之前,还有一个主activity跳转.代码如下: 请求activity代码: public class MachineInterface extends Activity { private ListView machineType; private Array

IOS - 网络(HTTP请求、同步请求、异步请求、JSON解析数据)

1 // 2 // ViewController.m 3 // IOS_0129_HTTP请求 4 // 5 // Created by ma c on 16/1/29. 6 // Copyright © 2016年 博文科技. All rights reserved. 7 // 8 9 #import "ViewController.h" 10 #import "MBProgressHUD+MJ.h" 11 12 @interface ViewController

Swift 网络请求数据与解析

一: Swift 网络数据请求与处理最常用第三方 又有时间出来装天才了,还是在学swift,从中又发现一些问题,这两天上网找博客看问题弄的真的心都累.博客一篇写出来,好多就直接照抄,就没有实质性的把问题解决了,只是在发表的博客数量上 + 1 !!真心没意思.. 看看在Swift中是在怎样请求数据,解析数据加载图片这些的,也使我们最基本最常见的用法了,先说说这几个三方库: 第一个: Alamofire  (它的原作者就是AFNetworking的原作者,这个就不多说了,你要知道AFNetworki

网络请求和json解析

请求使用AFN框架,json解析使用MJExtension框架 封装网络请求考虑扩展性: 协议头:http,https等 服务器地址或域名 API路径 请求方式:get,post等 传递的输入参数类型也不同 注意点: 设置HTTP请求序列化的文件为json格式 json转模型MJExtention: Model *modelResult = [Model objectWithKeyValues:responseObject]; responseObject为服务器返回的json对象 自定义的模型

iOS网络编程开发—JSON解析与XML解析

一.什么是JSON JSON是一种轻量级的数据格式,一般用于数据交互 服务器返回给客户端的数据,一般都是JSON格式或者XML格式(文件下载除外) JSON的格式很像OC中的字典和数组 {"name" : "jack", "age" : 10} {"names" : ["jack", "rose", "jim"]} 标准JSON格式的注意点:key必须用双引号 要想从