【发布时间】:2015-02-16 08:42:53
【问题描述】:
我第一次尝试用 volley 解析 json。我找到了一些例子,我学会了如何使用它。 但我有一个问题...... 我有这样的json
{
"Items ":
[
{
"Branch" :"mybranch",
"City" : "London"
},
{
"Branch" :"mybranch1",
"City" : "Paris"
},
{
"Branch" :"mybranch2",
"City" : "NY"
}
]
}
这是我的解析器代码
private void makeGetDictionaries13Request() {
showpDialog();
JsonObjectRequest jsonObjReq = new JsonObjectRequest(Method.GET,
urlgetbranchlist, null, new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
Log.e("TAG", response.toString());
try {
JSONArray mainjsonArray=response.getJSONArray("");
for (int i = 0; i < mainjsonArray.length(); i++) {
JSONObject j_object=mainjsonArray.getJSONObject(i);
System.out.println();
Log.e("City", j_object.getString("City"));
}
} catch (JSONException e) {
e.printStackTrace();
Toast.makeText(getApplicationContext(),
"Error: " + e.getMessage(),
Toast.LENGTH_LONG).show();
}
hidepDialog();
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
VolleyLog.d("TAG", "Error: " + error.getMessage());
Toast.makeText(getApplicationContext(),
error.getMessage(), Toast.LENGTH_SHORT).show();
// hide the progress dialog
hidepDialog();
}
});
// Adding request to request queue
AppController.getInstance().addToRequestQueue(jsonObjReq);
jsonObjReq.setRetryPolicy(new DefaultRetryPolicy(
15000,
DefaultRetryPolicy.DEFAULT_MAX_RETRIES,
DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
// Adding request to request queue
AppController.getInstance().addToRequestQueue(jsonObjReq);
}
我可以在日志中显示 jsonobject 结果,但我有凌空错误
no value for
对于我的选择,我在解析儿子时有问题..我做错了什么?
【问题讨论】:
标签: android json gson android-volley http-get