gpt4 book ai didi

Why - JsonParseException: Unexpected character '\' (code 92); expected a quote character enclosing value for 'version'?(为什么-JsonParseException:意外字符‘\’(代码92);需要‘Version’的引号字符括起来的值?)

转载 作者:bug小助手 更新时间:2023-10-25 09:16:22 25 4
gpt4 key购买 nike



I am trying to use XMLMapper and readTree() to parse an XML document that is in a String variable named "message". My code basically does the following:

我正在尝试使用XMLMapper和ReadTree()来解析一个名为“Message”的字符串变量中的XML文档。我的代码基本上执行以下操作:


            XmlMapper xmlMapper = new XmlMapper(); 

JsonNode node = null;
try {
node = xmlMapper.readTree(message.getBytes());
} catch (Exception e) {
parseLogger.error("------+++++ parse(): - **EXCEPTION** - e=[" + e + "]");
}

For a (really LONG) while, when I ran the app, it wasn't outputting any error or anything, then I was guessing the problem was that it didn't like the XML prolog at the beginning of the message:

有一段时间(真的很长时间),当我运行应用程序时,它没有输出任何错误或任何东西,然后我猜问题是它不喜欢消息开头的XML Prolog:


<?xml version="1.0" encoding="UTF-8" standalone="no"?>

So I added the following, to try to escape the double-quotes in the prolog;

因此,我添加了以下内容,以避免序言中的双引号;


message = message.replace("\"", "\\\"");

(FYI, there are no double-quotes in the message, other than the ones that are in the XML prolog line)

(仅供参考,除了XML序言行中的双引号外,消息中没有双引号)


and now, the modified prolog line looks like:

现在,修改后的序言行如下所示:


<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>

and it is getting past the xmlMapper.readTree(message.getBytes), but I am still getting this error message:

它正在通过xmlMapper.ReadTree(Message.getBytes),但我仍然收到这个错误消息:


JsonParseException: Unexpected character '\' (code 92); expected a quote character enclosing value for 'version'
at [row,col,system-id]: [1,15,"N/A"]]

The XML prolog looks all right/OK now (to me), so I don't understand why it is still complaining about the "unexpected ''"? Also, I am wondering about the part of the error message where it way "N/A"?

现在(在我看来)XML Prolog看起来还不错,所以我不明白为什么它还在抱怨“意外的‘’”?另外,我想知道错误消息中的哪一部分是“不适用”?


Can someone tell me why I am still getting that error?

谁能告诉我为什么我仍然收到这个错误?


Thanks,
Jim

谢谢,吉姆


EDIT1: Here's an example of one of the XML messages:

EDIT1:以下是其中一条XML消息的示例:


<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<record>
<rule>
<customer>1234</customer>
<schemaName>schema_name</schemaName>
<schemaVersion>1.0</schemaVersion>
</rule>
<identifier>
<XXX_USR_PN_IDXXX>12345</XXX_USR_PN_IDXXX>
</identifier>
<aRecord>
<XXX_USR_PN_ID>12345</XXX_USR_PN_ID>
<UserName>
<ENTPR_USER_NM_TX>Epple.12345</ENTPR_USER_NM_TX>
</UserName>
<person>
<ADM_ORG_CD>urn</ADM_ORG_CD>
<XXX_ASSOC_CD>urn:V01</XXX_ASSOC_CD>
<XXX_OCC_CD>123</XXX_OCC_CD>
<JB_XXX_OCC_CD>456</JB_XXX_OCC_CD>
<EMA>[email protected]</EMA>
<ORG_CD>11</ORG_CD>
<PERSONA_TYP_CD>JUNK122:GOOD321</PERSONA_TYP_CD>
<PG_CD>07</PG_CD>
<XYZEC_TYP_CD>12</XYZEC_TYP_CD>
<XYZ_CAT_CD>G</XYZ_CAT_CD>
</person>
<location>
<CTRY_CD>Yes</CTRY_CD>
</location>
</aRecord>
</record>

EDIT 2: One of my colleagues found the problem (and solution). He referenced this other SO thread:

编辑2:我的一个同事找到了问题(和解决方案)。他引用了另一条SO帖子:


NoSuchMethodError on com.fasterxml.jackson.dataformat.xml.XmlMapper.coercionConfigDefaults()

Com.fasterxml.jackson.dataformat.xml.XmlMapper.coercionConfigDefaults()上的NoSuchMethodError


in particular the comment from Marek F, "Marek F
Apr 13, 2022 at 10:44".

特别是来自马雷克·F的评论,“马雷克·F于2022年4月13日10:44”。


My understanding was that the OUD product was already using the 2.9.9 libs, so we had to add dependencies to the pom.xml to the 2.9.9 versions explicitly, and I think he did something to the Jenkins side also and then I rebuilt and it worked.

我的理解是,oud产品已经在使用2.9.9库,所以我们必须显式地将依赖项添加到2.9.9版本的pom.xml中,我认为他也对Jenkins方面做了一些改进,然后我重新构建,它起作用了。


更多回答

I don’t think you should escape the XML prolog. But where is the JSON where he is complaining about?

我认为您不应该逃避XML Prolog。但他抱怨的JSON在哪里?

"it wasn't outputting any error or anything," - so perhaps it was actually working?

“它没有输出任何错误或任何东西,”--所以它可能真的起作用了?

Before I added that code to escape the XML prolog, when I tested, it was doing the call to the readTree() but it wasn't logging any errors or anything (I have had tons of debug logging everything and try-catches all over and it never hit any of those. That was what I was referring to when I said "a LONG WHILE" :). To answer your question.. none of the output that I as seeing gave me the info to answer your question.

在我添加代码以逃避XML Prolog之前,当我测试时,它正在调用ReadTree(),但它没有记录任何错误或任何东西(我有大量的调试记录所有的事情和尝试-捕获,但它从来没有命中任何这些。这就是我说“很长一段时间”时所指的:)。回答你的问题..我看到的输出都没有给我提供回答你的问题的信息。

Can you show us the input that caused this? (BTW, escaping the XML prologue will not help)

你能给我们展示一下导致这一现象的输入因素吗?(顺便说一句,转义XML序言不会有什么帮助)

It's complaining about some JSON, not about XML. You haven't mentioned any JSON is your question. Find the JSON, and you will find the error.

它抱怨的是一些JSON,而不是XML。您没有提到任何JSON是您的问题。找到JSON,您就会找到错误。

优秀答案推荐
更多回答

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com