我正在尝试制作一个可以扫描条形码并查找JSON文件中与之相关的值的应用。唯一的问题是它一直跳过JsonObjectRequest方法。
这与此处的Json data array request keeps skipping onResponse非常相似。除了我不使用变量adaptermake。
public void jsonParse(String isbn) {
final String subisbn = isbn.substring(3,12);
// final List<String> li = new ArrayList<String>();
String url = "https://raw.githubusercontent.com/5Volts/FullSpeed/master/DA_ISBN2CLASS2.json";
// I put a breakpoint and found that this is where the code is skipped all the way down to mqueue
JsonObjectRequest request = new JsonObjectRequest(Request.Method.GET, url, null,
new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
try {
Log.d("Debugline",subisbn);
JSONArray jsonArray = response.getJSONArray(subisbn);
for (int i = 0; i < jsonArray.length(); i++) {
JSONObject obj = jsonArray.getJSONObject(i);
// li.add(nbook);
// mTextViewResult.setText(nbook);
// mTextViewResult.append(nbook+"\n");
}
} catch (JSONException e) {
e.printStackTrace();
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
error.printStackTrace();
}
});
mQueue.add(request);
}
@Override
public void onDetectedQrCode(Barcode barcode) {
if (barcode != null) {
jsonParse(barcode.rawValue);
Intent intent = new Intent();
intent.putExtra(BarcodeObject, barcode);
// Log.d("Debug",barcode.rawValue);
// System.out.println(barcode.rawValue);
setResult(CommonStatusCodes.SUCCESS, intent);
finish();
}
}