有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

c#无法读取JSON:无法构造java实例。util。从字符串值开始的日期

我正在使用REST SHARP并使用c#代码创建数据 my service is of Java service.

我得到了如下转换错误 当我经过CreatedDate = DateTime.Now

Json

{"id":123,"createdDate":"2015-08-06T12:18:32.8405195+05:30"}

C#RestSharp代码

  Customer cust = new Customer()
  cust.id=123;
  cust.createdDate = DateTime.Now;

  string jsonObject = JsonConvert.SerializeObject(cust , new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore });

  var restClient = new RestClient("http://myurl/");    
  var restRequest = new RestRequest("rest/", Method.POST);    
  restRequest.RequestFormat = DataFormat.Json;
  restRequest.AddParameter("application/json", jsonObject, ParameterType.RequestBody);
  restRequest.AddHeader("Content-Type", "application/json; charset=utf-8");    
  // execute the request
  RestSharp.IRestResponse restResponse = restClient.Execute(restRequest);

Could not read JSON: Can not construct instance of java.util.Date from String value '2015-08-06T12:13:01.8564244+05:30': not a valid representation (error: Failed to parse Date value '2015-08-06T12:13:01.8564244+05:30': Can not parse date \"2015-08-06T12:13:01.8564244+05:30\": 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\"))\n at [Source: org.apache.catalina.connector.CoyoteInputStream@19198464; line: 1, column: 69]


共 (0) 个答案