在Struts 2中使用OGNL进行JSON对象解析 [英] JSON object parsing using OGNL in struts 2

查看:142
本文介绍了在Struts 2中使用OGNL进行JSON对象解析的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个动作类,

public class DataProcessor extends ActionSupport{

    private JSONObject object;

    public JSONObject getObject() {
        return object;
    }

    public void setObject(JSONObject object) {
        this.object = object;
    }

    @Override
    public String execute() throws Exception {
        .......
        return SUCCESS;
    }
} 

我的XML映射就像

<package name="default" extends="struts-default" namespace="/">
   <action name="process" class="com.demo.DataProcessor">
      <result type="success">home.jsp</result>
   </action>
</package>

如果我写<s:property value="object"/>,则在jsp页面上

它会打印json数据. bt,如果我写

on jsp page if i write <s:property value="object"/> it prints json data. bt if i write

<s:property value="object.name"/>

<s:property value="#object.name"/>

<s:property value="${#object.name}"/>  it is printing nothing.

如何解析jsp页面中的json对象?

How can i parse json object in jsp page?

推荐答案

您不需要解析JSON,而需要从中获取值.假设您的objectorg.json.JSONObject,则可以通过调用get方法并将键作为字符串传递来从中获取价值.

You do not need to parse JSON you need to retrieve value from it. Assuming that your object is org.json.JSONObject you can get value from it by calling get method and passing key as string.

<s:property value="object.get('name')"/>

这篇关于在Struts 2中使用OGNL进行JSON对象解析的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆