-2

公共类 MainActivity 扩展 AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setcontentview(r.layout.activity_main);

    RequestQueue queue = Volley.newRequestQueue(this);
    String url = "https://developers.zomato.com/api/v2.1/search?&lat=27&lon=153";
    JsonObjectRequest postRequest = new JsonObjectRequest(Request.Method.GET, url, null,
            new Response.Listener<JSONObject>() {
                @Override
                public void onResponse(JSONObject response) {
                    // response
                    Log.d("Response", response.toString());
                }
            },
            new Response.ErrorListener() {
                @Override
                public void onErrorResponse(VolleyError error) {
                    // TODO Auto-generated method stub
                    Log.d("ERROR", "error => " + error.toString());
                }
            }
    ) {
        @Override
        public Map<String, String> getHeaders() throws AuthFailureError {
            Map<String, String> params = new HashMap<String, String>();
            params.put("user-key", "55a1d18014dd0c0dac534c02598a3368");
            params.put("Accept", "application/json");

            return params;
        }
    };
    queue.add(postRequest);
}

>

但我得到了所有不在附近的餐馆,请告诉我如何在应用程序中列出响应。

4

1 回答 1

0

您必须分别解析 json 数组和 json 对象中的 JSON 响应,

如需学习,请点击此链接:- 如何在 Android 中解析 JSON

那么您必须将列表传递到您的列表视图或回收器视图视图适配器。

为此,请遵循本教程:- https://medium.com/@peterekeneeze/parsing-remote-json-to-recyclerview-android-1ad927e96d58

于 2018-03-05T11:12:43.133 回答