我正在使用volley lib。在我的項目的每個活動中,我的第一個登錄頁面已經使用抽象的JSON對象請求方法(POST)完成,並且下一個活動無法分析。如何使用volley解析json數據
主屏幕的JSON數據:
{
"err-code": 5,
"job_details": [
{
"job_id": 33,
"job_no": "ES53-AF",
"contract_manager_id": 4,
"company_name": "A Construction Ltd",
"time_spent": 4.5
},
{
"job_id": 5,
"job_no": "ES1465-AF",
"contract_manager_id": 4,
"company_name": "Trios Property",
"job_description": "Carry out the rewire of ",
"time_spent": 26.5
},
{
"job_id": 81,
"job_no": "ES101-AF",
"contract_manager_id": 4,
"company_name": "Arden Construction Ltd",
"job_description": "Carry out works as per esti 3AQ",
"time_spent": 2.5
},
}]
}
代碼:
private void getDataNew()
{
String url = "http://103.5.103.8:067/ivservices/Webservices/joblisting";
HashMap<String, String> user = session.getUserDetails();
String token = user.get(SessionManager.KEY_TOKEN);
Log.e("token check kro", token);
final String role = user.get(SessionManager.KEY_ROLE);
Log.e("role", role);
String user_id = user.get(SessionManager.KEY_USERID);
// Log.e("user_id", user_id.toString());
Map<String, String> params = new HashMap();
params.put(KEY_TOKEN, token);
params.put(KEY_ROLE, role);
params.put(KEY_ID, user_id);
JSONObject parameters = new JSONObject(params);
JsonObjectRequest jsonRequest = new JsonObjectRequest(Request.Method.POST, url, parameters, new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
// Log.e("response mila", response.toString());
parseData(response);
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error)
{
error.printStackTrace();
//TODO: handle failure
}
});
Volley.newRequestQueue(this).add(jsonRequest);
}
[在Android中使用Volley解析JSON數據的可能的副本](http://stackoverflow.com/questions/18699988/parsing-data-from-json-using-volley-in-android) – Talha