java jsp jsonobject,在jsp中处理JSON对象

I have a JSON object sent from the browser to the jsp page.How do I receive that object and process it in jsp.Do I need any specific parsers? I have used the following piece of code.But it wouldn't work.Essentially I should read the contents of the object and print them in the jsp.

JSONObject inp=request.getParameter("param1");

%>

{%>

}

%>

解决方案

My preferred solution to this problem involves using a JSON parser that provides an output that implements the java.util.Map and java.util.List interface. This allows for simple parsing of the JSON structure in the JSP Expression language.

Here is an example using JSON4J provided with Apache Wink. The sample imports JSON data from a URL, parses it in a java scriptlet and browses the resulting structure.

String json = (String)pageContext.getAttribute("dataJson");

pageContext.setAttribute("parsedJSON", org.apache.commons.json.JSON.parse(json));

%>

Fetch the name of the node at index 1 : ${parsedJSON.node[1].name}

To make this clean, it would be preferable to create a JSTL tag to do the parsing and avoid java scriplet.

Fetch the name of the node at index 1 : ${parsedJSON.node[1].name}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值