简体   繁体   English

json.net:防止ulong以科学计数法序列化

[英]json.net: prevent ulong from getting serialized in scientific notation

I have a ulong which I want to serialize to JSON . 我有一个ulong ,我想序列化为JSON However, it gets serialized in scientific notation with data loss... How can I prevent that? 但是,它以科学计数法被序列化而导致数据丢失。如何防止这种情况发生? I think I could convert it to a string but I'm not sure if this is a good idea... 我想我可以将其转换为字符串,但是我不确定这是否是个好主意...

JavaScript does not support enough of numeric range to show ulong, so it does not make sense to represent it as numeric value in JSON. JavaScript不支持足够的数字范围来显示ulong,因此在JSON中将其表示为数字值没有意义。

If JSON ever will be used by JavaScript you'd better convert such values to string before/during conversion. 如果JavaScript将使用JSON,则最好在转换之前/转换过程中将这些值转换为字符串。

One possible conversion option - WCF & JSON: Serialize long as string or use decimal as suggested Json.NET crashes when serializing unsigned integer (ulong) array . 一种可能的转换选项-WCF和JSON:序列化为字符串,或按建议使用decimal 。序列化无符号整数(ulong)数组时,Json.NET崩溃

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM