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
发送为double,则将DeserializeObjecttake发送为整数
如果我们将Longitude /latitude
作为字符串发送,则错误为:
`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"
}
我们怎么能解决这个问题呢?