亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

使用 org.json 將 XML 轉換為 JSON 時出現 NoSuchMethod 錯誤

使用 org.json 將 XML 轉換為 JSON 時出現 NoSuchMethod 錯誤

喵喔喔 2021-09-26 17:02:29
我的項目使用 Spring Boot 2.0.4。我正在嘗試從文件中讀取 XML,然后將其轉換為 JSON。這曾經有效,但最近它停止工作并拋出以下異常;java.lang.NoSuchMethodError: org.json.JSONTokener.<init>(Ljava/io/Reader;)V    at org.json.XMLTokener.<init>(XMLTokener.java:57) ~[json-20180813.jar:na]    at org.json.XML.toJSONObject(XML.java:516) ~[json-20180813.jar:na]    at org.json.XML.toJSONObject(XML.java:548) ~[json-20180813.jar:na]    at org.json.XML.toJSONObject(XML.java:472) ~[json-20180813.jar:na]    at com.zf.trw.visualisation.parser.handler.AttritionHandler.extractLineData(AttritionHandler.java:32) ~[classes/:na]    at com.zf.trw.visualisation.parser.handler.HandlerImp.processFile(HandlerImp.java:79) ~[classes/:na]    at com.zf.trw.visualisation.shared.service.ParserService.manuallyProcessAttritionData(ParserService.java:85) ~[classes/:na]    at com.zf.trw.visualisation.parser.component.ScheduledTask.processAttritionDataFilesForAllLines(ScheduledTask.java:49) ~[classes/:na]    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_171]    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_171]    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_171]    at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_171]    at org.springframework.scheduling.support.ScheduledMethodRunnable.run(ScheduledMethodRunnable.java:84) ~[spring-context-5.0.8.RELEASE.jar:5.0.8.RELEASE]異常似乎表明它正在嘗試使用我在 POM 文件中指定的相同版本,這是最新版本。為什么我看到這個錯誤?
查看完整描述

3 回答

?
Cats萌萌

TA貢獻1805條經驗 獲得超9個贊

為我們做以下工作,在 pom.xml 中,我們排除了這兩個定義它們自己的類 org.json.JSONObject 的依賴項: com.unboundid.components:json和com.unboundid.components:mimepull。IE:


  <dependency>

        <groupId>org.springframework.boot</groupId>

        <artifactId>spring-boot-starter-web-services</artifactId>

        <exclusions>

            <exclusion>  <!-- declare the exclusion here -->

                <groupId>org.jvnet.mimepull</groupId>

                <artifactId>mimepull</artifactId>

            </exclusion>

        </exclusions>

        <version>${spring.boot.version}</version>

   </dependency>


查看完整回答
反對 回復 2021-09-26
?
MM們

TA貢獻1886條經驗 獲得超2個贊

或者,您也可以將 XML 轉換為 JSON,然后可以根據 JSON 模式驗證 JSON。


依賴:


<dependency>

    <groupId>com.github.fge</groupId>

    <artifactId>json-schema-validator</artifactId>

    <version>2.2.6</version>

</dependency>

代碼:


JsonNode node = JsonLoader.fromString(builder.toString());

JsonNode data = JsonLoader.fromString(serviceCreateJson.trim());

JsonSchemaFactory factory = JsonSchemaFactory.byDefault();

JsonSchema sch = factory.getJsonSchema(node);

ProcessingReport report = sch.validate(data);

boolean isSuccess = report.isSuccess();


查看完整回答
反對 回復 2021-09-26
  • 3 回答
  • 0 關注
  • 938 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號