如何获得没有方括号的jsonAray响应

时间:2017-09-06 09:22:37

标签: android json android-volley

如果没有方括号,我如何使用android volley获取json数据。只需使用jsonObjectRequest。

RequestQueue requestQueue = Volley.newRequestQueue(getActivity());
    JsonObjectRequest request = new JsonObjectRequest(Request.Method.GET, url,
            new Response.Listener<JSONObject>(){
                @Override
                public void onResponse(JSONObject response) {
                    try {
                        JSONObject obj = response.getJSONObject(??)
                        code = obj.getString("Code");
                        message = obj.getString("message");
                    } catch (JSONException e){
                        e.printStackTrace();
                    }
                }
            },
            new Response.ErrorListener() {
                @Override
                public void onErrorResponse(VolleyError error) {
                    Log.e("Volley", error.toString());

                    }
                }
            }
    );
    requestQueue.add(request);

Android排球码:

def matrixElementsSum(matrix):
    out = 0
    # locate the zeros' positions in array & replace element below
    for i,j in enumerate(matrix):
        for k,l in enumerate(j):
                if l == 0:
                break
            out += l 
    return out

0 个答案:

没有答案