NutzCN Logo
问答 http客户端,json提交,后台不能接收,报错解析json错误
发布于 88天前 作者 qq_2ac473ac 215 次浏览 复制 上一个帖子 下一个帖子
标签:

但是打印的字符串用postman,接口又可以正常解析
提交

 Request req = Request.create(url, METHOD.POST,Json.toJson(param,JsonFormat.compact()));

param是nutmap

new NutMap().setv("logs", listlogs)
public Object logs(@Param("logs") Logs[] _logs)

发送端报错

org.nutz.json.JsonException: !Json syntax error nearby [row:1,col:22 char ''], reason: 'Unexpect Char'
	at org.nutz.json.impl.JsonTokenScan.unexpectChar(JsonCompileImplV2.java:441)
	at org.nutz.json.impl.JsonTokenScan.readMap(JsonCompileImplV2.java:189)
	at org.nutz.json.impl.JsonTokenScan.read(JsonCompileImplV2.java:347)
	at org.nutz.json.impl.JsonCompileImplV2.parse(JsonCompileImplV2.java:27)
	at org.nutz.json.Json.fromJson(Json.java:57)
	at org.nutz.json.Json.parse(Json.java:92)
	at org.nutz.json.Json.fromJson(Json.java:73)
	at org.nutz.json.Json.fromJson(Json.java:178)
	at org.nutz.lang.Lang.map(Lang.java:1282)
	at com.fqx.zb.reportsys.job.HttpSender.post(HttpSender.java:31)
	at com.fqx.zb.reportsys.job.LogsJob.execute(LogsJob.java:54)
	at org.quartz.core.JobRunShell.run(JobRunShell.java:202)
	at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:573)

接收端报错

org.nutz.json.JsonException: !Json syntax error nearby [row:1,col:1 char 'l'], reason: 'Unexpect String = logs=%7Bt%3Daop.after%2C+tag%3D%E6%9F%A5%E8%AF%A2-%E9%A6%96%E9%A1%B5-%E9%94%80%E5%94%AE%E6%95%B0%E6%8D%AE%2C+source%3Dcom.fqx.zb.reportsys.module.DashBoardModule%23getSalesData%2C+username%3D9001%2F9001%2C+msg%3D%E5%8F%82%E6%95%B0%3D%7Bnow%3DSat+Jun+26+00%3A00%3A00+CST+2021%2C+session%3Dorg.apache.catalina.session.StandardSessionFacade%4042605d6e%7D%2C+createTime%3D2021-06-26+16%3A05%3A09%7D&logs=%7Bt%3Daop.after%2C+tag%3D%E6%9F%A5%E8%AF%A2-%E5%BD%93%E5%89%8D%E9%94%80%E5%94%AE-%E7%B1%BB%E5%88%AB%2C+source%3Dcom.fqx.zb.reportsys.module.DashBoardModule%23currentSalesByCls%2C+username%3D9001%2F9001%2C+msg%3D%E5%8F%82%E6%95%B0%3D%7Bnow%3DSat+Jun+26+00%3A00%3A00+CST+2021%2C+session%3Dorg.apache.catalina.session.StandardSessionFacade%4042605d6e%7D%2C+createTime%3D2021-06-26+16%3A05%3A09%7D&logs=%7Bt%3Daop.after%2C+tag%3D%E6%9F%A5%E8%AF%A2-%E9%A6%96%E9%A1%B5-%E6%8C%89%E5%A4%A9%E5%88%86%E7%B1%BB%2C+source%3Dcom.fqx.zb.reportsys.module.DashBoardModule%23recentSalesFordays%2C+username%3D9001%2F9001%2C+msg%3D%E5%8F%82%E6%95%B0%3D%7Bnow%3DSat+Jun+26+00%3A00%3A00+CST+2021%7D%2C+createTime%3D2021-06-26+16%3A05%3A11%7D&logs=%7Bt%3Daop.after%2C+tag%3D%E6%9F%A5%E8%AF%A2-%E5%AE%A2%E6%88%B7%2C+source%3Dcom.fqx.zb.reportsys.module.CustomerModule%23customers%2C+msg%3D%E5%8F%82%E6%95%B0%3D%7Bkeyword%3D%2C+pageIndex%3D1%2C+pageSize%3D20%7D%2C+createTime%3D2021-06-26+21%3A44%3A26%7D'
	at org.nutz.json.impl.JsonTokenScan.readObject(JsonCompileImplV2.java:304)
	at org.nutz.json.impl.JsonTokenScan.read(JsonCompileImplV2.java:360)
	at org.nutz.json.impl.JsonCompileImplV2.parse(JsonCompileImplV2.java:27)
	at org.nutz.json.Json.fromJson(Json.java:57)
	at org.nutz.mvc.adaptor.JsonAdaptor.getReferObject(JsonAdaptor.java:41)
	at org.nutz.mvc.adaptor.AbstractAdaptor.adapt(AbstractAdaptor.java:254)
	at org.nutz.mvc.impl.processor.AdaptorProcessor.process(AdaptorProcessor.java:30)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at org.nutz.mvc.impl.processor.ActionFiltersProcessor.process(ActionFiltersProcessor.java:58)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at org.nutz.mvc.impl.processor.ModuleProcessor.process(ModuleProcessor.java:123)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at org.nutz.mvc.impl.processor.EncodingProcessor.process(EncodingProcessor.java:27)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at org.nutz.mvc.impl.processor.UpdateRequestAttributesProcessor.process(UpdateRequestAttributesProcessor.java:15)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at com.fqx.zb.reportsys.LogTimeProcessor.process(LogTimeProcessor.java:18)
	at org.nutz.mvc.impl.NutActionChain.doChain(NutActionChain.java:44)
	at org.nutz.mvc.impl.ActionInvoker.invoke(ActionInvoker.java:67)
	at org.nutz.mvc.ActionHandler.handle(ActionHandler.java:31)
	at org.nutz.mvc.NutFilter.doFilter(NutFilter.java:202)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
	at com.alibaba.druid.support.http.WebStatFilter.doFilter(WebStatFilter.java:123)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:202)
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
	at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:541)
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:139)
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92)
	at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:688)
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:74)
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343)
	at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:373)
	at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65)
	at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:868)
	at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1594)
	at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
	at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
	at java.base/java.lang.Thread.run(Thread.java:835)

怎么回事啊?

4 回复

req.header设置一下content type

设置了的,还是不行啊

req.header("Content-Type", "application/json;charset=utf-8;");

DEBUG出来看里面的数据,怎么是这种格式啊

{logs=[{t=aop.after, tag=查询-首页-销售数据, source=com.fqx.zb.reportsys.module.DashBoardModule#getSalesData, username=9001/9001, msg=参数={now=Sat Jun 26 00:00:00 CST 2021, session=org.apache.catalina.session.StandardSessionFacade@42605d6e}, createTime=2021-06-26 16:05:09}, {t=aop.after, tag=查询-当前销售-类别, source=com.fqx.zb.reportsys.module.DashBoardModule#currentSalesByCls, username=9001/9001, msg=参数={now=Sat Jun 26 00:00:00 CST 2021, session=org.apache.catalina.session.StandardSessionFacade@42605d6e}, createTime=2021-06-26 16:05:09}, {t=aop.after, tag=查询-首页-按天分类, source=com.fqx.zb.reportsys.module.DashBoardModule#recentSalesFordays, username=9001/9001, msg=参数={now=Sat Jun 26 00:00:00 CST 2021}, createTime=2021-06-26 16:05:11}, {t=aop.after, tag=查询-客户, source=com.fqx.zb.reportsys.module.CustomerModule#customers, msg=参数={keyword=, pageIndex=1, pageSize=20}, createTime=2021-06-26 21:44:26}, {t=aop.after, tag=查询-首页-销售数据, source=com.fqx.zb.reportsys.module.DashBoardModule#getSalesData, username=9001/9001, msg=参数={now=Sun Jun 27 00:00:00 CST 2021, session=org.apache.catalina.session.StandardSessionFacade@6b0d39e0}, createTime=2021-06-27 12:28:54}, {t=aop.after, tag=查询-当前销售-类别, source=com.fqx.zb.reportsys.module.DashBoardModule#currentSalesByCls, username=9001/9001, msg=参数={now=Sun Jun 27 00:00:00 CST 2021, session=org.apache.catalina.session.StandardSessionFacade@6b0d39e0}, createTime=2021-06-27 12:28:54}, {t=aop.after, tag=查询-首页-按天分类, source=com.fqx.zb.reportsys.module.DashBoardModule#recentSalesFordays, username=9001/9001, msg=参数={now=Sun Jun 27 00:00:00 CST 2021}, createTime=2021-06-27 12:28:56}]}

以json重写bean的tostring解决了。。。。

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