Android 发布JSONObject并获取JSONArray请求截击
我目前正试图将JsonObject发布到API中,并从服务器获取JsonArray响应。我该怎么做呢?如果我尝试,会出现异常错误Android 发布JSONObject并获取JSONArray请求截击,android,json,post,android-volley,Android,Json,Post,Android Volley,我目前正试图将JsonObject发布到API中,并从服务器获取JsonArray响应。我该怎么做呢?如果我尝试,会出现异常错误 JsonObjectRequest postRequest = new JsonObjectRequest(Request.Method.POST, url_test,new JSONObject(params), new Response.Listener<JSONObject>() { @Over
JsonObjectRequest postRequest = new JsonObjectRequest(Request.Method.POST, url_test,new JSONObject(params),
new Response.Listener<JSONObject>() {
@Override
JsonObjectRequest postRequest=新的JsonObjectRequest(Request.Method.POST,url_测试,新的JSONObject(params),
新的Response.Listener(){
@凌驾
试试这些
url = "http://your Api post";
StringRequest postRequest = new StringRequest(Request.Method.POST, url,
new Response.Listener<String>()
{
@Override
public void onResponse(String response) {
// response
Log.d("Response", response);
}
},
new Response.ErrorListener()
{
@Override
public void onErrorResponse(VolleyError error) {
// error
Log.d("Error.Response", response);
}
}
) {
//You send the key and value to server you enter here
@Override
protected Map<String, String> getParams()
{
Map<String, String> params = new HashMap<String, String>();
params.put("key", "value");
return params;
}
};
queue.add(postRequest);
url=”http://your Api post”;
StringRequest postRequest=新的StringRequest(Request.Method.POST,url,
新的Response.Listener()
{
@凌驾
公共void onResponse(字符串响应){
//回应
Log.d(“响应”,响应);
}
},
新的Response.ErrorListener()
{
@凌驾
公共无效onErrorResponse(截击错误){
//错误
Log.d(“错误.响应”,响应);
}
}
) {
//将密钥和值发送到此处输入的服务器
@凌驾
受保护的映射getParams()
{
Map params=新的HashMap();
参数put(“键”、“值”);
返回参数;
}
};
添加(postRequest);
试试这些
url = "http://your Api post";
StringRequest postRequest = new StringRequest(Request.Method.POST, url,
new Response.Listener<String>()
{
@Override
public void onResponse(String response) {
// response
Log.d("Response", response);
}
},
new Response.ErrorListener()
{
@Override
public void onErrorResponse(VolleyError error) {
// error
Log.d("Error.Response", response);
}
}
) {
//You send the key and value to server you enter here
@Override
protected Map<String, String> getParams()
{
Map<String, String> params = new HashMap<String, String>();
params.put("key", "value");
return params;
}
};
queue.add(postRequest);
url=”http://your Api post”;
StringRequest postRequest=新的StringRequest(Request.Method.POST,url,
新的Response.Listener()
{
@凌驾
公共void onResponse(字符串响应){
//回应
Log.d(“响应”,响应);
}
},
新的Response.ErrorListener()
{
@凌驾
公共无效onErrorResponse(截击错误){
//错误
Log.d(“错误.响应”,响应);
}
}
) {
//将密钥和值发送到此处输入的服务器
@凌驾
受保护的映射getParams()
{
Map params=新的HashMap();
参数put(“键”、“值”);
返回参数;
}
};
添加(postRequest);
请告诉我抛出了哪个异常
好吗?发布崩溃日志和完整代码侦听JsonArray。您只需要发出json数组请求,因为您希望数组返回。您发布的数据并不重要我相信----请告诉我引发了哪个异常
?发布崩溃日志和完整代码..com.android.volley.ParseError:org.json.JSONException:我知道出了什么问题。我得到了一个json数组作为响应并像JsonObject一样对其进行解析。我的问题是如何使用volley创建post请求,以发布JsonObject并侦听JsonArray。您只需按照预期返回数组的方式发出json数组请求。发布什么数据我相信----