我想将json值传递给servlet来处理请求。
在客户端,我可以制作具有特殊字符的对象,例如“&” 。
我已将输入作为
"<h3>Welcome to ERP your name is #NAME#</h3>\n\n<h3> </h3>\n"
我使用
从json对象中检索值request.getParameter("jsonVal")
通过这样调用,“&amp; nbsp”之后的json值,不是由servlet采用的。输出是
"\"<h3>Welcome to ERP your name is #NAME#</h3>\\n\\n<h3>
并将错误显示为:
org.json.JSONException: Unterminated string at character 206
at org.json.JSONTokener.syntaxError(Unknown Source)
at org.json.JSONTokener.nextString(Unknown Source)
at org.json.JSONTokener.nextValue(Unknown Source)
at org.json.JSONObject.<init>(Unknown Source)
at org.json.JSONTokener.nextValue(Unknown Source)
at org.json.JSONArray.<init>(Unknown Source)
at org.json.JSONTokener.nextValue(Unknown Source)
at org.json.JSONObject.<init>(Unknown Source)
at org.json.JSONTokener.nextValue(Unknown Source)
at org.json.JSONObject.<init>(Unknown Source)
at org.json.JSONObject.<init>(Unknown Source)
at erp.controller.Controller.doPost(Controller.java:49)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:647)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1023)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
如何处理这个问题?
提前致谢..
答案 0 :(得分:0)
获取request.getParameter(“ jsonVal”)后,尝试使用JSON Viewer并确定什么是特殊字符。回车+换行符与JSONTokener有关,因此,您可以对其进行修剪并使用它。