【问题标题】:Big Json data in Java servletJava servlet 中的大 Json 数据
【发布时间】:2013-11-12 15:53:43
【问题描述】:

我使用 java servlet,我想从客户端接收大 json 数据。

我的客户代码是

 url: "http://localhost:8080/JsonTest/setJson",
 type: "POST",
 dataType: 'json',
 contentType: 'application/json',
 data:{json:str},

我的服务器代码是

String json=request.getParameter("json");

但是json变量是null

谁能帮帮我?

【问题讨论】:

  • JSON 将写入正文中。使用HttpServletRequestgetInputStream 方法从请求正文中读取JSON。然后使用 JSON 解析器进行解析。
  • 你想要做的例子在这里stackoverflow.com/questions/3831680/…

标签: java mysql ajax json post


【解决方案1】:

在数据上尝试 JSON.stringify:

url: "http://localhost:8080/JsonTest/setJson",
type: "POST",
dataType: 'json',
contentType: 'application/json',
data: JSON.stringify({json:str}),

或者如果 str 已经是一个 json 字符串:

url: "http://localhost:8080/JsonTest/setJson",
type: "POST",
dataType: 'json',
contentType: 'application/json',
data: str,

【讨论】:

  • 嗯,它解决了你的问题吗?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2011-11-24
  • 2019-03-17
  • 1970-01-01
  • 1970-01-01
  • 2012-04-27
  • 2014-10-16
  • 1970-01-01
相关资源
最近更新 更多