Android 应用程序通过服务将数据从 android sqlite 数据库传输到 sql server db。这工作正常。问题是双精度类型值,它转换为整数(并非仅适用于 GPS 位置坐标)。
这是我的代码:
JSONArray jaVisitDetail= new JSONArray();
StringBuffer visitDetail = new StringBuffer();
visitDetail.append("{\"WMVisitDetail\":");
for (int i = 0; i < stringList.size(); i++) {
ArrayList<?> arrayList = (ArrayList<?>) stringList.get(i);
ArrayList<?> list = arrayList;
if(((String) list.get(20)) != null && !((String) list.get(20)).equals("")) {
//DecimalFormat df = new DecimalFormat("#0.0000");
visitDe.put("Latitude",Double.parseDouble((String)list.get(20)));
//visitDe.put("Latitude",df.format(Double.parseDouble((String)list.get(20))));
//visitDe.put("Latitude",(String)list.get(20));
}else {
visitDe.put("Latitude",0.0000);
}
if(((String) list.get(21)) != null && !((String) list.get(21)).equals("")) {
//DecimalFormat df = new DecimalFormat("#0.0000");
visitDe.put("Longitude",Double.parseDouble((String)list.get(21)));
//visitDe.put("Longitude",df.format(Double.parseDouble((String)list.get(21))));
//visitDe.put("Longitude",(String)list.get(21));
}else {
visitDe.put("Longitude",0.0000);
}
jaVisitDetail.put(visitDe);
}
visitDetail.append(jaVisitDetail.toString());
visitDetail.append("}");
这是 C# 代码:
public bool convertJSONToDataSet(string strBusinessUnit, string strExecutiveCode, string strTableName, string jsonContent)
{
bool status =false;
try
{
DataSet ds = JsonConvert.DeserializeObject<DataSet>(jsonContent);
DataTable dt = ds.Tables[0];
status = UpdateUploadData(strBusinessUnit, strExecutiveCode, strTableName, dt);
}
catch (FaultException err)
{
status = false;
}
catch (Exception error)
{
string gg = error.Message;
Console.WriteLine(gg);
status = false;
}
return status;
}
如果我们发送Longitude /latitude
作为双精度然后 DeserializeObject 将其作为整数
如果我们发送Longitude /latitude
as 字符串,那么错误是:
`Input string was not in a correct format.Couldn't store <6.9292> in Latitude Column. Expected type is Int64.`
这是一组 json 数据
{
"ExecutiveCode":"EXEC03",
"ReasonCode":" ",
"SurveyNumber":" ",
"RetailerCode":"2975",
"UploadedType":" ",
"CallStartTime":"09:11:58",
"ActualValue":"30600",
"UploadedOn":" ",
"Status":"1",
"MTDAcheivedValue":0,
"ActiveStatus":"1",
"UploadFlag":"1",
"VisitNumber":"83",
"BusinessUnit":"MASS",
"UploadedMethod":" ",
"RetailerCodeSon":"",
"Latitude":"6.9294",
"VisitSequence":"58",
"Longitude":"79.9038",
"RetailerType":" ",
"UploadedBy":" ",
"CallEndTime":"09:14:41"
}
我们如何解决这个问题?