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