我们的ocr引擎以json数据的形式返回结果:
{"WordText":"\"*EET","Left":88.0,"Top":153.0,"Height":7.0,"Width":21.0}
请注意,“WordText”的值在反斜杠后包含一个双引号。当我用json.dumps处理它时,它会得到一个“预期分隔符”错误。OCR引擎在文本中遇到双引号时会产生大量此类错误。似乎没有任何方法可以修改OCR的输出,所以我需要编写后处理代码来纠正这些错误
我很乐意消除任何不直接在冒号之后或逗号之前的双引号,但不知道如何在python或正则表达式中有效地实现它
有人有什么建议或工具可以解决这类json问题吗
这对额外的逃跑有帮助吗
Dump to JSON adds additional double quotes and escaping of quotes
这可能并不完美(我觉得使用两个正则表达式模式有点粗糙),但对于给定的JSON
此代码
输出
也许看看答案开头的那个额外的转义链接,看看是否有问题。这也可能是有用的
how to remove a back slash from a JSON file
***
更新:
***
下面是一段新代码,其中一个示例是两个正则表达式模式修复了损坏的JSON。我没有您的JSON,但它表明正则表达式应该有助于解决迄今为止描述的损坏问题。我对代码进行了注释以帮助解释它
代码:
产出:
如果您注释掉,正则表达式将替换
…并让pandas读取JSON it错误
…这是意料之中的
相关问题 更多 >
编程相关推荐