德国文化-用逗号从JSON获取双数 [英] German culture - get double number from JSON with a comma

查看:95
本文介绍了德国文化-用逗号从JSON获取双数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个供内部使用的MVC Web-API应用程序。我有一些带有表单和数字字段的页面。我需要在德国计算机上安装此软件,而用户只能是德国人。在德国,他们用 3,5代替 3.5(用逗号)。

I have an MVC Web-API application for inner use. I have some pages with forms and numeric fields. I need to install this on a German computer, and the users will be only Germans. In Germany they write "3,5" instead of "3.5" (with a comma).

在IIS配置中,区域性是不变区域性,并且由于计算机是德语-本地化为 de-DE。

In IIS configuration the culture is "Invariant culture" and since the computer is German - the localize is "de-DE".

当用户在字段中输入 3,5时-我在萤火虫中看到 3,5是JSON中发送的内容,但服务器将其获取为 35。

When the users write "3,5" in the field - I can see in firebug that "3,5" is what is sent in JSON, but the server gets it as "35".

我可以在服务器端处理它吗? (我不想更改json,因为我需要在每个字段和页面中进行操作)

Can I handle it on server-side? (I don't want to change the json because I'll need to do it in every field and page)

 using Newtonsoft.Json;
 using Newtonsoft.Json.Converters;
 public class ItemsController : ApiController, IDisposable
 {
        [Authorize(Roles = "Admin")]
        [HttpPost]
        public HttpResponseMessage UpdateItem(ItemViewModel itemVM)
        {
            // JSON data sent data.NumProp1 = "3,5"
            // itemVM.NumProp1 contains "35" instead of "3.5"
        }
}


推荐答案

您不应该本地化JSON-请参见 http://www.json.org 用于规范(仅将点显示为分隔符)和如何在JSON序列化时进行本地化?类似的问题。

You should not localize your JSON - see http://www.json.org for the spec (which only shows the dot as a separator) and How to localize when JSON-serializing? for a similar question.

我不建议您尝试读取自定义的JSON-现在听起来似乎是个捷径,但最后您根本就没有使用JSON。

I wouldn't recommend trying to read your customized JSON - it may sound like a quick win right now, but in the end you simply aren't using JSON.

这篇关于德国文化-用逗号从JSON获取双数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆