Android 如何使用截取解析json数据
我在用截击。在我的项目中的每个活动中,我的第一个登录页面都使用了截取JSON对象请求方法(POST),而下一个活动无法解析 主屏幕的Json数据:Android 如何使用截取解析json数据,android,json,android-volley,Android,Json,Android Volley,我在用截击。在我的项目中的每个活动中,我的第一个登录页面都使用了截取JSON对象请求方法(POST),而下一个活动无法解析 主屏幕的Json数据: { "err-code": 5, "job_details": [ { "job_id": 33, "job_no": "ES53-AF", "contract_manager_id": 4, "company_name": "A Construction Ltd", "tim
{
"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()
{
字符串url=”http://103.5.103.8:067/ivservices/Webservices/joblisting";
HashMap user=session.getUserDetails();
字符串令牌=user.get(SessionManager.KEY_令牌);
Log.e(“令牌检查kro”,令牌);
最后一个字符串role=user.get(SessionManager.KEY_角色);
Log.e(“角色”,角色);
字符串user\u id=user.get(SessionManager.KEY\u USERID);
//Log.e(“user_id”,user_id.toString());
Map params=新的HashMap();
参数put(密钥令牌,令牌);
参数put(关键角色、角色);
参数put(密钥ID、用户ID);
JSONObject参数=新的JSONObject(参数);
JsonObjectRequest jsonRequest=new JsonObjectRequest(Request.Method.POST、url、参数、new Response.Listener()){
@凌驾
公共void onResponse(JSONObject响应){
//Log.e(“response mila”,response.toString());
解析数据(响应);
}
},new Response.ErrorListener(){
@凌驾
公共无效onErrorResponse(截击错误)
{
错误。printStackTrace();
//TODO:处理失败
}
});
newRequestQueue(this.add)(jsonRequest);
}
试试这个
注意同时检查您的json删除,}before]比没有语法错误响应的情况下要多
试试看{
int err_code=response.getInt(“err code”);
JSONArray JSONArray=response.getJSONArray(“作业详细信息”);
对于(int i=0;i请尝试此操作
注意同时检查您的json删除,}before]比没有语法错误响应的情况下要多
试试看{
int err_code=response.getInt(“err code”);
JSONArray JSONArray=response.getJSONArray(“作业详细信息”);
对于(int i=0;iremove Extra},从json中删除
您在回复@Er.Arjun saini的json解析代码中犯了一个错误
这个错误就在这一行:
JSONArray JSONArray=Object.getJSONArray(“err code”)
应该是这样的:
JSONArray JSONArray=Object.getJSONArray(“作业详细信息””
确保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
}
]
}
并尝试这段代码,希望它能工作,如果不工作,请分享logcat错误和异常
try {
JSONObject Object=new JSONObject(response);
int code = Object.getInt("err-code");
if (code == 0) {
JSONArray jsonArray = Object.getJSONArray("job_details");
List<JobList> jobListArray=new ArrayList<JobList>();
for (int i = 0; i <= jsonArray.length(); i++) {
JSONObject jsonObject = (JSONObject) jsonArray.get(i);
JobList model_joblist=new JobList();
model_joblist.setJobno(jsonObject.getString(JobList.JOB_NO));
model_joblist.setJobid(jsonObject.getInt(JobList.JOB_ID));
model_joblist.setDescreption(jsonObject.getString(JobList.JOB_DESCRIPTION));
jobListArray.add(model_joblist);
}
}
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
试试看{
JSONObject对象=新的JSONObject(响应);
int code=Object.getInt(“错误代码”);
如果(代码==0){
JSONArray JSONArray=Object.getJSONArray(“作业详细信息”);
List jobListArray=new ArrayList();
对于(int i=0;iremove Extra},从json中删除
您在回复@Er.Arjun saini的json解析代码中犯了一个错误
这个错误就在这一行:
JSONArray JSONArray=Object.getJSONArray(“err code”)
应该是这样的:
JSONArray JSONArray=Object.getJSONArray(“作业详细信息””
确保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
}
]
}
并尝试这段代码,希望它能工作,如果不工作,请分享logcat错误和异常
try {
JSONObject Object=new JSONObject(response);
int code = Object.getInt("err-code");
if (code == 0) {
JSONArray jsonArray = Object.getJSONArray("job_details");
List<JobList> jobListArray=new ArrayList<JobList>();
for (int i = 0; i <= jsonArray.length(); i++) {
JSONObject jsonObject = (JSONObject) jsonArray.get(i);
JobList model_joblist=new JobList();
model_joblist.setJobno(jsonObject.getString(JobList.JOB_NO));
model_joblist.setJobid(jsonObject.getInt(JobList.JOB_ID));
model_joblist.setDescreption(jsonObject.getString(JobList.JOB_DESCRIPTION));
jobListArray.add(model_joblist);
}
}
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
试试看{
JSONObject对象=新的JSONObject(响应);
int code=Object.getInt(“错误代码”);
如果(代码==0){
JSONArray JSONArray=Object.getJSONArray(“作业详细信息”);
List jobListArray=new ArrayList();
对于(int i=0;i可能重复字符串job_no=jsonObjectdetail.getString(“job_no”);此行无响应抱歉更改响应。getInt(“错误代码”)5959426选项可能是:您可以为用户和管理员创建不同的屏幕。登录时检查登录是否为管理员,然后将其移动到管理员活动,等等……否则打开用户活动……第二个解决方案是,如果您有相同的屏幕,但数据不同,则在检查用户或管理员后加载相关数据……尝试适合您的……嗨……我没有她的问题…我如何实现我的android应用程序..对于管理员主屏幕不同和用户主屏幕不同,除了同一appone中的登录屏幕外,解决方案可以是:您可以为用户和管理员设置不同的屏幕。登录时检查登录是否为admin,然后将其移动到admin活动等…否则打开用户活动..第二步解决方案如果您有相同的屏幕但不同的数据,那么在检查用户或管理员后加载相关数据…尝试适合您的。。。。。