德国文化 - 用逗号从 JSON 中获取双数

German culture - get double number from JSON with a comma(德国文化 - 用逗号从 JSON 中获取双数)
本文介绍了德国文化 - 用逗号从 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"时 - 我可以在 firebug 中看到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 中获取双数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

DispatcherQueue null when trying to update Ui property in ViewModel(尝试更新ViewModel中的Ui属性时DispatcherQueue为空)
Drawing over all windows on multiple monitors(在多个监视器上绘制所有窗口)
Programmatically show the desktop(以编程方式显示桌面)
c# Generic Setlt;Tgt; implementation to access objects by type(按类型访问对象的C#泛型集实现)
InvalidOperationException When using Context Injection in ASP.Net Core(在ASP.NET核心中使用上下文注入时发生InvalidOperationException)
LINQ many-to-many relationship, how to write a correct WHERE clause?(LINQ多对多关系,如何写一个正确的WHERE子句?)