nutz版本:1.r.68.v20200427
字符串如下:
{
"access_token": "0f740c97-74fd-4f8a-a41a-bdb46d69d3d5",
"token_type": "bearer"
}
String content = "{\n" +
" \"access_token\": \"0f740c97-74fd-4f8a-a41a-bdb46d69d3d5\",\n" +
" \"token_type\": \"bearer\"\n" +
"}";
Map map = Json.fromJsonAsMap(NutMap.class, content);
System.out.println(map);
json String转map报错:
Exception in thread "main" org.nutz.castor.FailToCastObjectException: Fail to cast from <java.lang.String> to <org.nutz.lang.util.NutMap> for {0f740c97-74fd-4f8a-a41a-bdb46d69d3d5}
at org.nutz.castor.Castors.cast(Castors.java:263)
at org.nutz.castor.Castors.castTo(Castors.java:317)
at org.nutz.mapl.impl.convert.ObjConvertImpl.injectMap(ObjConvertImpl.java:156)
at org.nutz.mapl.impl.convert.ObjConvertImpl.inject(ObjConvertImpl.java:87)
at org.nutz.mapl.impl.convert.ObjConvertImpl.convert(ObjConvertImpl.java:72)
at org.nutz.mapl.Mapl.maplistToObj(Mapl.java:34)
at org.nutz.json.Json.parse(Json.java:94)
at org.nutz.json.Json.fromJson(Json.java:88)
at org.nutz.json.Json.fromJson(Json.java:110)
at org.nutz.json.Json.fromJsonAsMap(Json.java:421)
at JsonTest.main(JsonTest.java:40)