本文介绍了Android studio,错误:org.json.jsonexception:类型为java.lang.string的customerid的值无法转换为int的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好友,



成功登录后,我正在尝试使用REST网络服务下载数据。解析时我收到错误:org.json.JSONException:类型为java.lang.String的CustomerId的值无法转换为int

------------- ----------

public static void Download_Data(int UserId,String wsUsername,String wsPassword,boolean isDbProd,

Object callBackClass,Method callBackMethod)throws例外

{

downloadDataCallBackClass = callBackClass;

downloadDataCallBackMethod = callBackMethod;



尝试{

方法dlGetData = DL.class.getMethod(downloadDataResult,JSONObject.class,Exception.class);



Map<串,> parameters = new HashMap< string,>();

parameters.put(UserId,UserId);

parameters.put(wsUsername,wsUsername);

parameters.put(wsPassword,wsPassword);

parameters.put(IsDbProduction,isDbProd);



new WebService_Call()。execute(URL,NAMESPACE,http://tempuri.org/+ WebMethods.android_GetData.toString(),

WebMethods.android_GetData.toString(), DL.class,dlGetData,参数);

}

catch(例外e)

{

全新例外(DL.Get_Data():\ n+ e.getMessage());

}

}

--- -----------------------------

public static void downloadDataResult(JSONObject JSO,Exception e)抛出异常{

尝试{

if(e == null){

DL.downloadDataInfo = JS O.getJSONArray(Items)。getJSONObject(0);

saveItems();

}

downloadDataCallBackMethod.invoke(downloadDataCallBackClass,JSO ,e);

} catch(Exception ex){

ex.printStackTrace();

}

}

--------------------------------

public static void saveItems()

{

DBHelper helper = new DBHelper(context);

ItemDL items = new ItemDL();



//解析JSON数据......

尝试{

items.setItemId(DL.downloadDataInfo.getInt( ItemId));

items.setItemCode(DL.downloadDataInfo.getString(ItemCode));

items.setCustName(DL.downloadDataInfo.getString(CustomerName) ));

items.setCustMobile(DL.downloadDataInfo.getString(CustomerMobile));

items.setErrMsg (DL.downloadDataInfo.getString(ErrorMsg));

items.setProcedureId(DL.downloadDataInfo.getInt(ProcedureId));

items.setStatementId(DL .downloadDataInfo.getInt(StatmentID));

items.setCustomerId(DL.downloadDataInfo.getInt(CustomerId)); < - 这行代码抛出异常

items.setExceptionId(DL.downloadDataInfo.getInt(ExceptionID));

items.setInserted(DL.downloadDataInfo。 getBoolean(IsInserted));



helper.insertItems(items);

} catch(异常e){

e.printStackTrace();

System.out.println(Thrown Exception:+ e.getMessage());

}

}

------------------------------------- -

我从这行代码中得到错误:items.setCustomerId(DL.downloadDataInfo.getInt(CustomerId));

------ --------------------------------

返回的JSON对象:



{ItemCode:EE4xyzxyx,

ItemId:55452134,

ExceptionID: - 1 ,

ErrorMsgNo:,

Lat:,

UserID:6510,

UserName:,

IsInserted:,

客户名称:,

CustomerMobile:,

PostServiceId: - 1,

Sp_Status:,

CustomerId:,

ProcedureId:198,

UserFullName: aasafe,

ImagePic:,

StatmentID: - 1,

ErrorMsg: ,

Lon:}

-------------------------- ---

亲切检查,让我知道我做错了什么。



我尝试过:



Android Studio,错误:org.json.JSONException:类型为java.lang.String的CustomerId上的值无法转换为int

Friends,

After successful login, I'm trying to download data using REST web service. While parsing I'm getting error : org.json.JSONException: value at CustomerId of type java.lang.String cannot be converted to int
-----------------------
public static void Download_Data(int UserId, String wsUsername, String wsPassword, boolean isDbProd,
Object callBackClass, Method callBackMethod) throws Exception
{
downloadDataCallBackClass=callBackClass;
downloadDataCallBackMethod=callBackMethod;

try {
Method dlGetData=DL.class.getMethod("downloadDataResult",JSONObject.class,Exception.class);

Map<string,> parameters=new HashMap<string,>();
parameters.put("UserId",UserId);
parameters.put("wsUsername",wsUsername);
parameters.put("wsPassword",wsPassword);
parameters.put("IsDbProduction",isDbProd);

new WebService_Call().execute(URL, NAMESPACE, "http://tempuri.org/" + WebMethods.android_GetData.toString(),
WebMethods.android_GetData.toString(), DL.class, dlGetData, parameters);
}
catch (Exception e)
{
throw new Exception("DL.Get_Data():\n" + e.getMessage());
}
}
--------------------------------
public static void downloadDataResult(JSONObject JSO,Exception e)throws Exception {
try {
if (e == null) {
DL.downloadDataInfo = JSO.getJSONArray("Items").getJSONObject(0);
saveItems();
}
downloadDataCallBackMethod.invoke(downloadDataCallBackClass, JSO, e);
} catch (Exception ex) {
ex.printStackTrace();
}
}
--------------------------------
public static void saveItems()
{
DBHelper helper = new DBHelper(context);
ItemDL items=new ItemDL();

//parse JSON DATA...
try {
items.setItemId(DL.downloadDataInfo.getInt("ItemId"));
items.setItemCode(DL.downloadDataInfo.getString("ItemCode"));
items.setCustName(DL.downloadDataInfo.getString("CustomerName"));
items.setCustMobile(DL.downloadDataInfo.getString("CustomerMobile"));
items.setErrMsg(DL.downloadDataInfo.getString("ErrorMsg"));
items.setProcedureId(DL.downloadDataInfo.getInt("ProcedureId"));
items.setStatementId(DL.downloadDataInfo.getInt("StatmentID"));
items.setCustomerId(DL.downloadDataInfo.getInt("CustomerId")); <-- This line of code throws exception
items.setExceptionId(DL.downloadDataInfo.getInt("ExceptionID"));
items.setInserted(DL.downloadDataInfo.getBoolean("IsInserted"));

helper.insertItems(items);
} catch (Exception e) {
e.printStackTrace();
System.out.println("Thrown Exception: "+e.getMessage());
}
}
--------------------------------------
I'm getting Error from this line of code: items.setCustomerId(DL.downloadDataInfo.getInt("CustomerId"));
--------------------------------------
Returned JSON Object:

{"ItemCode":"EE4xyzxyx",
"ItemId":"55452134",
"ExceptionID":"-1",
"ErrorMsgNo":"",
"Lat":"",
"UserID":"6510",
"UserName":"",
"IsInserted":"",
"CustomerName":"",
"CustomerMobile":"",
"PostServiceId":"-1",
"Sp_Status":"",
"CustomerId":"",
"ProcedureId":"198",
"UserFullName":"aasafe",
"ImagePic":"",
"StatmentID":"-1",
"ErrorMsg":"",
"Lon":""}
-----------------------------
Kind check and let me know what I'm doing wrong.

What I have tried:

Android Studio, Error: org.json.JSONException: value at CustomerId of type java.lang.String cannot be converted to int

推荐答案


这篇关于Android studio,错误:org.json.jsonexception:类型为java.lang.string的customerid的值无法转换为int的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 18:10