【发布时间】:2019-08-07 13:08:48
【问题描述】:
希望你们能给我解释一下,我是第一次做这个 JSON,还有 2 天时间来完成。
bookByID = (TextView) findViewById(R.id.tvBookbyid);
btSearch = (Button) findViewById(R.id.btSearchbook);
etId = (EditText) findViewById(R.id.etID);
queue = Volley.newRequestQueue(this);
btSearch.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
loadBook();
}
});
}
private static final String JSON_URL = "deleted";
这是方法:
private void loadBook() {
queue = Volley.newRequestQueue(this);
int id = Integer.parseInt((String) etId.getText().toString());
StringRequest request = new StringRequest(Request.Method.GET, JSON_URL + id, new Response.Listener<String>() {
@Override
public void onResponse(String response) {
try {
抱歉这个间距,但它一直说我必须解释所有代码
JSONObject object=new JSONObject(response);
for(int i=0;i<object.length();i++) {
int bookid = object.getInt("id");
String title =object.getString("title");
String isbn =object.getString("isbn");
String description =object.getString("description");
int price =object.getInt("price");
String currencyCode =object.getString("currencyCode");
String author =object.getString("author");
list.add(new Book(bookid,title,isbn,description,price,currencyCode,author));
// Toast.makeText(getApplicationContext(), "Hello end", Toast.LENGTH_SHORT).show();
}
【问题讨论】: