公共类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);
}
&GT;
但我得到的所有餐馆都不在附近,请告诉我如何在申请表中列出回复。
答案 0 :(得分:0)
你必须分别解析json数组和json对象中的JSON响应,
学习请点击此链接: - How to parse JSON in Android
然后您必须通过列表到列表视图或回收站视图视图适配器。
以下是本教程: - https://medium.com/@peterekeneeze/parsing-remote-json-to-recyclerview-android-1ad927e96d58