2017-05-08 24 views
0

我有一个JSON字符串。当我通过POST方法将视图中的字符串发送到我的控制器时,此JSON的一个属性是datetime,它以“dd/mm/yyyy”格式映射。但是,当我通过GET方法发送相同的JSON字符串时,相同的属性映射格式为“mm/dd/yyyy”,对于天数大于12的日期,该属性保留为NULL。如何解决此问题?这可能是Visual Studio问题吗?我正在使用巴西的日期格式。DateTime格式对于POST和GET方法是不同的

+0

?你能分享一些代码吗? –

+0

如果你使用json.net,看看这个:https://stackoverflow.com/questions/18635599/specifying-a-custom-datetime-format-when-serializing-with-json-net – user1845593

回答

0

你需要具体文化上的获取请求。因为浏览器使用不同的文化比你的服务器,他们应该匹配,

DateTime dt = DateTime.Now; 
    // Sets the CurrentCulture property to U.S. English or whatever your browser using . 
    Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US"); 
    // Displays dt, formatted using the ShortDatePattern 
    // and the CurrentThread.CurrentCulture. 
    Console.WriteLine(dt.ToString("d")); 

更多的检查:你用哪个库序列化JSON格式的对象https://msdn.microsoft.com/en-us/library/5hh873ya(v=vs.90).aspx