在解析此代码时,我面临的问题是什么?我不知道如何在android java中的数组中获取数组,这是我的JSON数据,我正在寻找最简单的方法通过一个齐射
{
"msg": "Records fetched",
"data": [
[
{
"totalSale": 418.89
}
]
]
}
我正在获得这些双重括号并且无法获得Total Sale的价值。
编辑2 我正在使用此代码,并在最后得到此响应和错误。
String url = "http://94.200.123.222:3434/dailysale/2018-05-03";
RequestQueue queue = Volley.newRequestQueue(Dailysales.this); // this = context
JsonObjectRequest jsonObjReq = new JsonObjectRequest(
Request.Method.GET,url,null,
new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
JSONObject status = null;
try {
JSONObject jo= new JSONObject(String.valueOf(response));
JSONArray ja = jo.getJSONArray("data");
JSONArray jv = ja.getJSONArray(0);
JSONArray jvv = jv.getJSONArray(0);
JSONObject sttus = response.getJSONObject(null);
int Resultcode = status.getInt("totalSale");
Log.d("REs", ""+Resultcode);
//
} catch (JSONException e) {
e.printStackTrace();
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
VolleyLog.d("EROOOOOOOOOOOOOOOOOOOOOR", "Error: " + error.getMessage());
}
}) {
/**
* Passing some request headers
* */
@Override
public Map<String, String> getHeaders() throws AuthFailureError {
HashMap<String, String> headers = new HashMap<String, String>();
headers.put("Content-Type", "application/json; charset=utf-8");
return headers;
}
};
queue.add(jsonObjReq);
错误是
org.json.JSONException: Value {"totalSale":7559.41} at 0 of type org.json.JSONObject cannot be converted to JSONArray