NutzCN Logo
问答 我把Json转换NutMap出现错误
发布于 2745天前 作者 蛋蛋的忧伤 2098 次浏览 复制 上一个帖子 下一个帖子
标签:

我在将字符串json转换成NutMap时报错,求解

@org.junit.Test
	public void test6(){
		String str = "content:{\"access_token\":\"3FL1_0oHp5mjBiy8O-rwfj-Yu4R6lVK_QyEb9c_RW4DFltHC3FqgYjFs74seHvDF_jkHM8lEAKOsbJdoqskRjP3740VSe54_itcc3GV4mI02N0lt7Dheln6aQ5gJSQWpZEUhAEAOTJ\",\"expires_in\":7200}";
		NutMap nm = (NutMap) Json.fromJson(str);
		System.out.println(nm);
	}

日志:

org.nutz.json.JsonException: !Json syntax error nearby [row:1,col:1 char 'c'], reason: 'Unexpect String = content:{"access_token":"3FL1_0oHp5mjBiy8O-rwfj-Yu4R6lVK_QyEb9c_RW4DFltHC3FqgYjFs74seHvDF_jkHM8lEAKOsbJdoqskRjP3740VSe54_itcc3GV4mI02N0lt7Dheln6aQ5gJSQWpZEUhAEAOTJ","expires_in":7200}'
	at org.nutz.json.impl.JsonTokenScan.readObject(JsonCompileImplV2.java:297)
	at org.nutz.json.impl.JsonTokenScan.read(JsonCompileImplV2.java:354)
	at org.nutz.json.impl.JsonCompileImplV2.parse(JsonCompileImplV2.java:26)
	at org.nutz.json.Json.fromJson(Json.java:42)
	at org.nutz.json.Json.fromJson(Json.java:144)
	at com.wechat.test.Test.test6(Test.java:207)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
	at java.lang.reflect.Method.invoke(Unknown Source)
	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.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)
	at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:678)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)

3 回复

贴错了贴错了.这是代码

@org.junit.Test
	public void test6(){
		String str = "{\"access_token\":\"3FL1_0oHp5mjBiy8O-rwfj-Yu4R6lVK_QyEb9c_RW4DFltHC3FqgYjFs74seHvDF_jkHM8lEAKOsbJdoqskRjP3740VSe54_itcc3GV4mI02N0lt7Dheln6aQ5gJSQWpZEUhAEAOTJ\",\"expires_in\":7200}";
		NutMap nm = (NutMap) Json.fromJson(str);
		System.out.println(nm);
	}

这是真实报错日志:

java.lang.ClassCastException: java.util.LinkedHashMap cannot be cast to org.nutz.lang.util.NutMap
	at com.wechat.test.Test.test6(Test.java:207)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
	at java.lang.reflect.Method.invoke(Unknown Source)
	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.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)
	at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:678)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)


NutMap nm = Json.fromJson(str, NutMap.class);

感谢wendal耐心回答,感谢不嫌弃我菜. 泪奔~

添加回复
请先登陆
回到顶部