问题描述
我正在生成一个 json 对象,
I am generating a json object,
{
"number":0100
}
当这个对象在 C# 中使用 Newtonsoft.Json 反序列化时,0100 被视为八进制数,因为前导零.有没有办法覆盖此功能并使其将数字视为十进制整数?
When this object is deserialized in C# using Newtonsoft.Json, 0100 is treated as an octal number because of the leading zero. Is there a way to override this functionality and make it consider the number as a decimal integer?
推荐答案
我看过 JsonTextReader.ParseNumber() (数字读取的魔法"发生的方法).我会说这是不可行的.八进制大小写特别处理
I've looked at JsonTextReader.ParseNumber() (the method where the "magic" of number reading happen). I'll say that it isn't doable. The octal case is especially handled
bool flag2 = c == '0' ...
然后
long value2 = text2.StartsWith("0x", StringComparison.OrdinalIgnoreCase) ?
Convert.ToInt64(text2, 16) :
Convert.ToInt64(text2, 8); // Here OCTAL!!!
我还没有找到任何方法来覆盖这个方法(除了重写所有在 Json 解析中执行 everything 的 Read() 方法)
I haven't found any way to override this method (other than re-writing all the Read() method that does everything in Json parsing)
这篇关于覆盖 Json 反序列化带有前导零的数字作为十进制而不是八进制值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!


大气响应式网络建站服务公司织梦模板
高端大气html5设计公司网站源码
织梦dede网页模板下载素材销售下载站平台(带会员中心带筛选)
财税代理公司注册代理记账网站织梦模板(带手机端)
成人高考自考在职研究生教育机构网站源码(带手机端)
高端HTML5响应式企业集团通用类网站织梦模板(自适应手机端)