【问题标题】:Diffrence between JsonObjectRequest & JsonArrayRequest in volley in android?android 凌空中 JsonObjectRequest 和 JsonArrayRequest 之间的区别?
【发布时间】:2015-01-30 13:19:15
【问题描述】:

大家好,我正在使用 volley 向服务器发送请求。我正在向服务器发送一些参数并获得一个 json 数组和 json 对象作为响应。截至目前,我正在使用 JsonObjectRequest 自定义请求来获取响应。如果响应是 JsonArray,我会得到 json 数组,如果响应是 jsonObject,那么我会得到 json 对象。那么我应该遵循哪种方法来获取响应?

Following is the code for sending request 
public void sendData()
{
    RequestQueue que=Volley.newRequestQueue(this);
    Map<String, String> params = new HashMap<String, String>();
    params.put("fname",fname );
    params.put("lname",lname );
    params.put("email",email );
    params.put("pswd",password);


     final ProgressDialog dialog = new ProgressDialog(HealthCreateAccount.this);
     dialog.setTitle("Please Wait");
     dialog.setMessage("Creating Account..");
     dialog.setCancelable(false);
     dialog.show();

    CustomRequest jsObjRequest = new CustomRequest(Method.POST, url, params, new Response.Listener<JSONObject>() {

                @Override
                public void onResponse(JSONObject response)
                {
                    dialog.dismiss();
                    Toast.makeText(getApplicationContext(), response.toString(), Toast.LENGTH_SHORT).show();


                }
            }, new Response.ErrorListener() {

                @Override
                public void onErrorResponse(VolleyError response) {
                    dialog.dismiss();
                    Toast.makeText(getApplicationContext(), "Unable to Create Account!", Toast.LENGTH_SHORT).show();
                    Log.i("RAE",response.toString());
                }
            });
    que.add(jsObjRequest);

}

【问题讨论】:

标签: android json http android-volley


【解决方案1】:

Json Object & Json 数组是类型请求。 Json 对象将尝试获取 json 数组,其中 json 对象将获取 json 对象。但是您可以使用 json 对象并在 json 对象中创建 json 数组。

【讨论】:

    猜你喜欢
    • 2016-05-10
    • 1970-01-01
    • 2019-01-03
    • 2021-09-04
    • 1970-01-01
    • 1970-01-01
    • 2016-05-28
    • 2018-01-14
    • 1970-01-01
    相关资源
    最近更新 更多