问题描述
我发送给我的一些 JSON 在尝试反序列化时会中断.它似乎包含一个带有 ?
的黑色菱形.我看不到该字符,但它显然存在并且在我的系统上出现故障.
I have some JSON being sent to me that breaks when it is trying to be deserialized. It seems to contain a black diamond with a ?
in it. I cannot see the character but it is obviously there and it is failing on my system.
如何摆脱这种情况并仍然保留我的 JSON 以进行反序列化?
How do I get rid of this and still leave my JSON intact for deserialization?
更新:
以下是我的 JSON 中间内容的示例:
Here is a example of what will be in the middle of my JSON:
"UDF5" : "�65",
我什至愿意通过 RegEx 从我的 JSON 中完全删除这个属性.
I am even open to just removing this property from my JSON altogether via RegEx.
推荐答案
如回答:使用正则表达式删除一段字符串(JSON 字符串),并根据您在该问题中提供的格式(我假设将编辑成这个):
As answered for: remove piece of string (JSON string ) with regex and based on the formatting you provide in that question (and I am assuming will edit into this one):
假设我可以依赖您上面显示的格式,并且它是每个正在运行的正则表达式之一,这可以像这样简单地完成
Assuming I can rely on the formatting you show above and it is one of these per regex being run this can be accomplished as simply as something like
([\S\s]*\"])\"UDF5\" : \"[\S\s]*?\",([\S\s]*)
使用反向引用 $1$2 引用 UDF5 字段前后的部分来写回.
Using the back reference $1$2 referencing the parts before and after the UDF5 field to write back out.
如果要删除换行符,我现在不会这样做.这可能会更好 - 如果其他人有时间纠正或提供额外的答案.但为了让您获得紧急修复,我希望这会有所帮助.
If there is a newline there to remove I am not doing it right now. This could be better - if someone else has time to correct or provide an additional answer. But in the interests of getting you an emergency fix I hope this helps.
这篇关于在反序列化之前从我的 JSON 中删除奇怪的隐藏字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!