简体   繁体   English

C#序列化程序类编码问题

[英]C# Serializer class Encoding Issue

I'm really not understanding where these characters are coming from. 我真的不明白这些字符来自哪里。 I am populating a custom class object and then serializing it to disk and getting strange characters in the result like this: 我正在填充一个自定义类对象,然后将其序列化到磁盘上,并在结果中得到奇怪的字符,如下所示:

<Address1>_x0031_0028_x0020_N_x0020_30th_x0020_PL</Address1>

Where the correct answer is this: 正确答案是这样的:

<Address1>10028 N 30th PL</Address1>

When I step through the code, each of these object properties look good, it is only after they serialize that strange characters are injected. 当我单步执行代码时,这些对象属性中的每一个看起来都不错,只有在序列化之后才注入奇怪的字符。 What I am not certain of, is if the characters originate from its source (a Nexus DB table which) and I just can't see the strange characters when stepping through the code in VS, or if indeed the characters are a result of serializing from the object itself. 我不确定的是,这些字符是否源自其来源(Nexus DB表),而在VS中遍历代码时我只是看不到奇怪的字符,或者这些字符确实是序列化的结果从对象本身。 FYI, The object class source is actually a schema object that I've converted to a class. 仅供参考,对象类源实际上是我已转换为类的架构对象。

Another note: this problem isn't occurring on every element, just a handful of them. 另一个注意事项:并不是每个元素都出现此问题,只是其中的几个。

Thanks for any help on this. 感谢您对此的任何帮助。

Karl.. 卡尔

Solving my own problem. 解决我自己的问题。 The problem was that I had defined a field in my schema as xs:ncname type, and then when serializing the values in the data source did not conform to this type so spaces and leading numbers were translated accordingly on serialization. 问题是我在架构中将字段定义为xs:ncname类型,然后在序列化数据源中的值时不符合该类型,因此在序列化时相应地转换了空格和前导数字。

The solution was to correctly define the field as xs:string. 解决方案是将字段正确定义为xs:string。

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

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