当服务器返回以下JSON为JsonObjectRequest错误没有发现合适的构造 -使用凌空
[ { “USER_ID”:1, “first_name的”: “亚历克斯”, “姓氏”: “goft”, “密码”: “doom00”, “电子邮件”: “[email protected]”, “用户名”: “alexgoft” } ]
我尝试使用凌空它检索用下面的函数 -
public void makeRequest() {
final String HOST = "http://10.0.2.2:3000/";
final String url = HOST + "get_data?type=user&username=alexgoft";
RequestQueue queue = Volley.newRequestQueue(context);
Toast.makeText(context, url, Toast.LENGTH_LONG).show();
// prepare the Request
JsonObjectRequest getRequest = new JsonObjectRequest(Request.Method.GET, url,
new Response.Listener<JSONArray>() {
@Override
public void onResponse(JSONArray response) {
Toast.makeText(context, "In succ", Toast.LENGTH_LONG).show();
try {
returned_json = response.getJSONObject(0);
} catch (JSONException e) {
e.printStackTrace();
}
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Toast.makeText(context, "In error", Toast.LENGTH_LONG).show();
Toast.makeText(context, error.toString(), Toast.LENGTH_LONG).show();
error.getStackTrace();
Log.d("error", error.toString());
}
});
queue.add(getRequest);
}
的问题是,我碰到下面的错误 -
Error:(46, 40) error: no suitable constructor found for JsonObjectRequest(int,String,<anonymous Listener<JSONArray>>,<anonymous ErrorListener>)
constructor JsonObjectRequest.JsonObjectRequest(int,String,Listener<JSONObject>,ErrorListener) is not applicable
(argument mismatch; <anonymous Listener<JSONArray>> cannot be converted to Listener<JSONObject>)
constructor JsonObjectRequest.JsonObjectRequest(String,JSONObject,Listener<JSONObject>,ErrorListener) is not applicable
(argument mismatch; int cannot be converted to String)
什么我需要做的,这样returned_json
将包含返回的JSON从主机?
这是怎么看的IDE -
等待,如果有编译时错误,那么怎么来回应? –