我正在努力通过我的第一个Android应用程序处理天气卫星数据。我使用JSON从远程服务器检索平铺图像的时间。由于缺乏java经验,我无法获得jResponse,因此应用程序的其他部分可以使用这些数据。有没有办法从on响应方法中获取jResponse(JSONArray)?当我尝试改变返回JSONArray的方法时,它将撤消覆盖。我很困难,并会非常感谢任何帮助。如何从AndroidSDK中的Volley请求存储JSONARRAY?
public JSONArray getJson(final int i,String sectorName){
times = new JSONArray();
String url = "https://storage.googleapis.com/satsquatch-tiles-dev/GOES16_"+String.format("%02d",i)+"_"+sectorName+".json";
final JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.GET, url, null,
new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
Log.d("test", "Success");
try {
JSONArray jResponse = response.getJSONArray("times");
for (int count = 0; count < jResponse.length(); count++){
Log.d("Array_times",jResponse.get(count).toString());
}
} catch (JSONException e) {
e.printStackTrace();
}
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Log.d("test", "JSON Request Failure Check URL!");
}
});
//add request to queue
queue.add(jsonObjectRequest);
return times;
为什么不在jsonObjectRequest之前声明jResponse? –
我想在解析后使用JSON数组或ArrayList。@ Ashish是否允许我从getJSON方法返回jResponse?如果是这样,我相信这将解决我的问题。 –
你会显示你的响应层次? –