1. 程式人生 > >JSON格式對接過程隨筆

JSON格式對接過程隨筆

tostring result 交易 ack bin image instance jackson blog

技術分享
 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("")做的交易

JSON格式對接過程隨筆