包含 “é 时,将 Json 反序列化为对象时出错è à”人物
我尝试使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
该错误似乎表明您在字符串末尾缺少引号?
为了更好地帮助我们,您可以发布有效和无效的 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?
除了已接受的答案之外,.net-3.5 JSON 实现。 .net-3.5 会导致如下所示的证明字符串出现此错误。但是,如果您将项目切换到 .net -4.0 或更高,问题立即消失。
Besides the accepted answer, there seems to be an issue in .net-3.5 JSON implementation. Plain UTF-8 JSON serialization and deserialization in .net-3.5 leads to this error on proof-string shown below. But if you switch the project to .net-4.0 or higher, the issue immediately disappears.