包含 “é 时,将 Json 反序列化为对象时出错è à”人物

发布于 2024-11-07 04:39:34 字数 559 浏览 0 评论 0原文

我尝试使用 DataContractJsonSerializer 将 JSON 字符串反序列化为对象。一切正常,直到 JSON 字符串包含一些法语字符,例如 é è à。它会抛出异常:

反序列化 ** 类型的对象时出错。预期为标记“”,但找到了“é”。

有人知道如何解决它吗?

{ "features": [ { "id": "0c50cdc5-da97-45be-aad2-ad1433d8e285LastEditedFeature", "wkt": "", "fieldValues": [ { "Key": "formeID", "Value": "1" }, { "Key": "calqueID", "Value": "1" }, { "Key": "featureID", "Value": "0c50cdc5-da97-45be-aad2-ad1433d8e285" }, { "Key": "Name", "Value": "ABCDé" } ] } ] }

恐怕它是由“ABCDé”字符串中的é引起的。

I tried using DataContractJsonSerializer to deserialize the JSON string to object. All works fine until the JSON string contains some French characters, such as é è à. It will throw the exception:

There was an error deserializing the object of type **. The token '"' was expected but found 'é'.

Is there anybody know to resolve it?

{ "features": [ { "id": "0c50cdc5-da97-45be-aad2-ad1433d8e285LastEditedFeature", "wkt": "", "fieldValues": [ { "Key": "formeID", "Value": "1" }, { "Key": "calqueID", "Value": "1" }, { "Key": "featureID", "Value": "0c50cdc5-da97-45be-aad2-ad1433d8e285" }, { "Key": "Name", "Value": "ABCDé" } ] } ] }

I'm afraid that maybe it's caused by the é in "ABCDé" string.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

姐不稀罕 2024-11-14 04:39:34

该错误似乎表明您在字符串末尾缺少引号?

为了更好地帮助我们,您可以发布有效和无效的 JSON 吗?

That error would seem to indicate that you are missing a quote at the end of your string?

To better help us, could you post the JSON that works and doesn't work?

时间你老了 2024-11-14 04:39:34

除了已接受的答案之外, JSON 实现。 会导致如下所示的证明字符串出现此错误。但是,如果您将项目切换到 或更高,问题立即消失。

string proofString = "";
for (int i = 1; i <= 0xffff; i++) {
    if (i >= 0xd800 && i < 0xe000) continue; // skip code points not belonging to UTF-8
    proofString += Strings.ChrW(i);
} 

Besides the accepted answer, there seems to be an issue in JSON implementation. Plain UTF-8 JSON serialization and deserialization in leads to this error on proof-string shown below. But if you switch the project to or higher, the issue immediately disappears.

string proofString = "";
for (int i = 1; i <= 0xffff; i++) {
    if (i >= 0xd800 && i < 0xe000) continue; // skip code points not belonging to UTF-8
    proofString += Strings.ChrW(i);
} 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文