zoukankan      html  css  js  c++  java
  • jsonobject.fromobject方法转换中出现的问题

    出错信息如下:

    Method public java.lang.String org.apache.commons.lang.exception.NestableRuntimeException.getMessage(int) threw an exception when invoked on net.sf.json.JSONException: A JSONObject text must begin with '{' at character 1 of judd The problematic instruction: ---------- ==> ${msgs[0][0]} [on line 76, column 25 in org/apache/struts2/dispatcher/error.ftl] ---------- Java backtrace for programmers: ---------- freemarker.template.TemplateModelException: Method public java.lang.String org.apache.commons.lang.exception.NestableRuntimeException.getMessage(int) threw an exception when invoked on net.sf.json.JSONException: A JSONObject text must begin with '{' at character 1 of judd at freemarker.ext.beans.SimpleMethodModel.exec(SimpleMethodModel.java:130)

    解决方案:

    jsonobject只能转换map类型或者是bean类型的数据,而不能转变action中的属性。

    如果需要action返回一个json字符串,只需要注解即可;

    jsonarray只能转换list对象;

    jsonobject.fromobject(括号中是bean或者是map对象,不能是action中的属性)

    注意!

     

    另外小计如下:

    8  json通过struts2后台传递json对象或者是json字符串;

    8.1 如果是简单的传入字符串,只需要加入一个struts2-json-plugin-2.3.1.2.jar包即可;
    8.2 如果是需要传入前台的是一个jsonobject,那么需要的有额外的6个包,必不可少,一定要注意:
          1.commons-beanutils-1.7.0.jar
          2.commons-collections-3.2.1.jar
          3.commons-lang-2.3.jar
          4.commons-logging-1.0.4.jar
          5.ezmorph-1.0.3.jar
          6.json-lib-2.1.jar
         另外必须包如下:
          7.struts2-json-plugin-2.3.1.2.jar

          以上的包都可以在struts2中找到,注意事项:
           8.2.1   jsonobject的使用方法,可以转换一个对象,也可以自己加入一个对象;
           8.2.2   jsonobject和jsonarray只是新增了一个json中的对象,而不是action中返回的json对象只有这一个转化后的json对象;
           8.2.4   在action中使用jsonobject或者是jsonarray后不会改变已有的json返回对象;

  • 相关阅读:
    UOJ #455 [UER #8]雪灾与外卖 (贪心、模拟费用流)
    Codeforces 482E ELCA (LCT)
    Codeforces 798D Mike and distribution (构造)
    AtCoder AGC017C Snuke and Spells
    HDU 6089 Rikka with Terrorist (线段树)
    HDU 6136 Death Podracing (堆)
    AtCoder AGC032D Rotation Sort (DP)
    jenkins+python+kubectl实现批量更新k8s镜像
    Linux 下载最新kubectl版本的命令:
    jenkins X 和k8s CI/CD
  • 原文地址:https://www.cnblogs.com/seniortestingdev/p/2501693.html
Copyright © 2011-2022 走看看