private List<gson.DataBean>arrGson;//請求的數據
//請求數據的方法
public void initData()
{
RequestQueue mQueue = Volley.newRequestQueue(getApplicationContext());
String url ="http://www.fashions88.com/you/HBooks88/GetBooks88Data.php?&Type=NewBook";
StringRequest stringRequest_get = new StringRequest(url, new Response.Listener<String>() {
@Override
public void onResponse(String response) {
Log.d("TAG", response);
Gson gsons = new Gson();
gson gs = gsons.fromJson(response,gson.class);
arrGson = gs.getData();
// for (gson.DataBean beans : gs.getData()) {
// Log.d("data", beans.getName());
// }
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Log.e("TAG", error.getMessage(), error);
}
});
mQueue.add(stringRequest_get);
}
//////////////////
模型
package bluewebprinter.pericles.net.bluewebprinter;import java.util.List;/** * Created by you on 2017/3/28. * http://www.fashions88.com/you/HBooks88/GetBooks88Data.php?&Type=NewBook * http://www.fashions88.com/you/HBooks88/GetBooks88Data.php?&Type=Other */public class gson { private List<DataBean> data; public List<DataBean> getData() { return data; } public void setData(List<DataBean> data) { this.data = data; } public static class DataBean { /** * Name : 綜合能力測驗復習指導 * Author : 本書編寫組 編 * USPrice : 6.83 * PhotoPath : http://img33.dangdang.com/70/31/20691763-1_o.jpg * Book_No : 9787010076812 * Publisher : 人民出版社 * Saved_PhotoPath : 20091015/9787010076812.jpg * Publish_Date_T : 22099る * SCDName : 政治 */ private String Name; private String Author; private String USPrice; private String PhotoPath; private String Book_No; private String Publisher; private String Saved_PhotoPath; private String Publish_Date_T; private String SCDName; public String getName() { return Name; } public void setName(String Name) { this.Name = Name; } public String getAuthor() { return Author; } public void setAuthor(String Author) { this.Author = Author; } public String getUSPrice() { return USPrice; } public void setUSPrice(String USPrice) { this.USPrice = USPrice; } public String getPhotoPath() { return PhotoPath; } public void setPhotoPath(String PhotoPath) { this.PhotoPath = PhotoPath; } public String getBook_No() { return Book_No; } public void setBook_No(String Book_No) { this.Book_No = Book_No; } public String getPublisher() { return Publisher; } public void setPublisher(String Publisher) { this.Publisher = Publisher; } public String getSaved_PhotoPath() { return Saved_PhotoPath; } public void setSaved_PhotoPath(String Saved_PhotoPath) { this.Saved_PhotoPath = Saved_PhotoPath; } public String getPublish_Date_T() { return Publish_Date_T; } public void setPublish_Date_T(String Publish_Date_T) { this.Publish_Date_T = Publish_Date_T; } public String getSCDName() { return SCDName; } public void setSCDName(String SCDName) { this.SCDName = SCDName; } }}