当前位置: 首页 > 知识库问答 >
问题:

Groovy脚本中的JsonSlurper parseText异常:java.lang.ClassCastException:[B不能强制转换为[C

卢英范
2023-03-14

我想在Groovy中解析Json,但它抛出异常,不知道我的代码有什么问题,需要一些帮助

[环境:]

jdk-9.0.4

ide:想法

朗:太棒了

异常如下:警告:发生了非法反射访问操作警告:org . code Haus . groovy . reflection . cached class $ 3 $ 1(file:/C:/Users/hhbst/)的非法反射访问。grad le/caches/modules-2/files-2.1/org . codehaus . groovy/groovy-All/2 . 3 . 11/f6b 34997 d04c 1538 ce 451d 3955298 f 46 FD B4 DBD 4/groovy-All-2 . 3 . 11 . jar)到方法java.lang.Object.finalize()警告:请考虑将此情况报告给org . codehaus . groovy . reflection . cached class$3$1的维护人员

Java . lang . classcastexception:[B不能转换为[C

at groovy.json.internal.FastStringUtils$StringImplementation$1.toCharArray(FastStringUtils.java:88)
at groovy.json.internal.FastStringUtils.toCharArray(FastStringUtils.java:175)
at groovy.json.internal.BaseJsonParser.parse(BaseJsonParser.java:103)
at groovy.json.JsonSlurper.parseText(JsonSlurper.java:208)
at groovy.json.JsonSlurper$parseText.call(Unknown Source)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:45)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:108)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116)
at com.hypers.test.apitest.util.JsonUtilTest.JsonParaTest(JsonUtilTest.groovy:20)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:564)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)

以退出代码-1完成的进程

@Test
void JsonParaTest(){
    def jsonSlurper = new JsonSlurper()
    def object = jsonSlurper.parseText('{ "name": "John Doe" }')

    assert object.name == 'John Doe'
}

暂时还没有答案

 类似资料: