【发布时间】:2015-12-21 05:16:57
【问题描述】:
您好,我是 Android 的初学者,我遇到了这个问题。所以这就是我正在尝试使用凌空响应对象来做的事情
private void parseJSONResponse(JSONObject response)
{
int a = jsonObject.getInt("xxx"); //get 1st parameter
String mid = jsonObject.getString("Movieid"); //get an id
String murl = genrate(mid); //send id to genrate method which returns another url
String x=createmovieJSON(murl);//method to create JsonObjectRequest object using the new url and return string.
info.add(new information(a,x)); //pass int and string for generating a card layout
}
createmovieJSON 方法如下:
public String createmovieJSON(String strurl)
{
final String[] str=(null); //str[0] contains null
RequestQueue requestQueue = Singelton.instantinate().getRequestqueue();
JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.POST, strurl,
new Response.Listener<JSONObject>()
{
@Override
public void onResponse(JSONObject response)
{
str[0] = parseMovieResponse(response); //str[0] contains required string say'abc'
new Toastnotify(getApplicationContext(),str[0]);
}
},
new Response.ErrorListener(){...
});
requestQueue.add(jsonObjectRequest);
new Toastnotify(getApplicationContext(),str[0]);
return(str[0]); //str[0] contains null instead of abc
}
'final String[]' 数组是在更正 onResponse 方法中的错误“将 str 转换为最后一个元素数组”时自动创建的。为什么它创建一个数组而不只是使 str 最终?(我尝试手动执行此操作但它给出了同样的错误)。我知道它是一个内部类,因此我必须将它设为 final 但为什么是数组?
那么如何将 onResponse 中 str[0] 中返回的字符串发送回 parseJSONResponse 方法中的调用方法?
【问题讨论】:
标签: java android json android-volley