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

1

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

问题描述

限时送ChatGPT账号..

我有一个供内部使用的 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 中获取双数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

The End

相关推荐

C# 中的多播委托奇怪行为?
Multicast delegate weird behavior in C#?(C# 中的多播委托奇怪行为?)...
2023-11-11 C#/.NET开发问题
6

参数计数与调用不匹配?
Parameter count mismatch with Invoke?(参数计数与调用不匹配?)...
2023-11-11 C#/.NET开发问题
26

如何将代表存储在列表中
How to store delegates in a List(如何将代表存储在列表中)...
2023-11-11 C#/.NET开发问题
6

代表如何工作(在后台)?
How delegates work (in the background)?(代表如何工作(在后台)?)...
2023-11-11 C#/.NET开发问题
5

没有 EndInvoke 的 C# 异步调用?
C# Asynchronous call without EndInvoke?(没有 EndInvoke 的 C# 异步调用?)...
2023-11-11 C#/.NET开发问题
2

Delegate.CreateDelegate() 和泛型:错误绑定到目标方法
Delegate.CreateDelegate() and generics: Error binding to target method(Delegate.CreateDelegate() 和泛型:错误绑定到目标方法)...
2023-11-11 C#/.NET开发问题
14