为什么RestSharp使用utc格式序列化日期时间属性

时间:2016-03-24 05:13:46

标签: restsharp

我正在使用这样的东西。

public class Program
    {
        public static void Main(string[] args)
        {

            RestCustomRequest rt= new RestCustomRequest();
            rt.Test =DateTime.Now.ToString();
            rt.testDate = DateTime.Now;

            string x = ExecuteRestAPI(rt,"");

            //Your code goes here
            Console.WriteLine(x);

        }

      public static string ExecuteRestAPI(RestCustomRequest request,string BaseURL)
      {
        RestRequest apiRequest = new RestSharp.RestRequest();
        apiRequest.RequestFormat = DataFormat.Json;
        apiRequest.AddHeader("Content-Type", "application/json");
        apiRequest.AddBody(request);
        var x = Newtonsoft.Json.JsonConvert.SerializeObject(apiRequest);
        return x;
        RestClient rc = new RestClient(BaseURL);
        IRestResponse resp = rc.Execute(apiRequest);


      }

    }

public class RestCustomRequest
{
  public string Test {get;set;}
  public DateTime testDate{get;set;}
} 

以下数据显示了restsharp序列化的问题

 {
            "Name": "application/json",
            "Value": "{\"Test\":\"3/24/2016 10:33:35 AM\",\"testDate\":\"2016-03-24T05:03:35.8288773Z\"}",
            "Type": 4,
            "ContentType": null
        },

但是,如果我们使用AddObject()而不是AddBody(),它就可以工作。 AddBody()与Addobject()

的区别

0 个答案:

没有答案