if (dr.Table.Columns[j].DataType.ToString() == "System.DateTime") { if (dr[dr.Table.Columns[j].ColumnName.ToString()] != DBNull.Value) { result += AddDoubleYH(Convert.ToDateTime(dr[dr.Table.Columns[j].ColumnName.ToString()]).ToString("yyyy-MM-dd HH:mm:ss")); //result += JsonConvert.SerializeObject(dr[dr.Table.Columns[j].ColumnName.ToString()]); } }
result_memo":"RuntimeException: com.fasterxml.jackson.databind.exc.InvalidFormatException: Can not construct instance of java.util.Date from String value '2017-07-19 08:08:08': not a valid representation (error: Failed to parse Date value '2017-07-19 08:08:08': Can not parse date "2017-07-19 08:08:08": not compatible with any of standard forms ("yyyy-MM-dd'T'HH:mm:ss.SSSZ", "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", "EEE, dd MMM yyyy HH:mm:ss zzz", "yyyy-MM-dd"))
解决方法:
C#端使用下面的代码时,java可以成功交易,但是接收到日期时间数据与C#端相差8个小时
result += JsonConvert.SerializeObject(dr[dr.Table.Columns[j].ColumnName.ToString()]);
随后,java端做了修改调整,使用tostring("")做的交易
转义字符""
private string queryStatus() { //构造url var baseUrl = "http://yesfp.yonyoucloud.com"; var url = baseUrl + "/invoiceclient-web/api/invoiceApply/queryInvoiceStatus?appid=yesfpTester"; var req = (HttpWebRequest)WebRequest.Create(url); var paraEnvoice = "fpqqlsh=" + saleNum; var param = paraEnvoice; //设置消息头 // var bs = Encoding.ASCII.GetBytes(param); var bs = Encoding.UTF8.GetBytes(param); req.Method = "POST"; req.ContentType = "application/x-www-form-urlencoded;charset=" + Encoding.UTF8.WebName; req.Headers.Add("sign", Sign(paraEnvoice)); //放入签名信息在消息头 req.ContentLength = bs.Length; //发送请求 using (var reqStream = req.GetRequestStream()) { reqStream.Write(bs, 0, bs.Length); reqStream.Close(); } //获取请求 using (var response = (HttpWebResponse)req.GetResponse()) { var responseStream = response.GetResponseStream(); if (responseStream == null) { return "false"; } using (var reader = new StreamReader(responseStream, Encoding.UTF8)) { var responseData = reader.ReadToEnd(); eInvoiceQRet qret = JsonConvert.DeserializeObject<eInvoiceQRet>(responseData); if (qret.statuscode == publicInfo.EINVOICE_Q_SUC) { JObject urlret = (JObject)JsonConvert.DeserializeObject(qret.data); eInvoiceUrlData urldata = JsonConvert.DeserializeObject<eInvoiceUrlData>(urlret["data"].ToString()); return "true"; } return "false"; } } }
直接使用eInvoiceQRet转换时,发现“{"fpqqlsh":"300011700040092","code":"0000","msg":"查询成功","statuscode":"4","status":"开票成功","data":"{"data":"{\"bmbBbh\":\"13.0\",\"bz……”内嵌的data含有转义符号,DeserializeObject发生异常未处理Newtonsoft.Json.JsonSerializationException。
解决方法:见上面代码,采用string先取出数据后,再转成相应对象