0

所以,在我折腾了 3 个小时后终于寻求帮助

<%@ page import="net.sf.json.*" %>

..
.
.



<%
     while (rs.next()) {
     %>
      <%
    json = (JSONObject) JSONSerializer.toJSON(rs.getString(3));
    System.out.println(json.toString());

    System.out.println(json.getString('site_caption'));//Compiler failed
    System.out.println(json.get('site_caption'));//Compier failed

    }
    %> 

上面的代码在控制台打印

{ "font_color" : "#0079cd",
  "site_background" : { "color" : "",
      "image" : "",
      "selected" : "image"
    },
  "site_caption" : "<p>Site Caption</p>\r\n",
  "site_description" : "<p>Site Description</p>\r\n",
  "site_logo" : { "image" : "1361858536dyn007or53.gif",
      "selected" : "image",
      "text" : ""
    }
}

但是当我尝试打印时

    System.out.println(json.getString('site_caption'));//Compiler failed
    System.out.println(json.get('site_caption'));//Compier failed

甚至没有给出正确的错误信息

我被同样的错误信息骚扰

Compile failed; see the compiler error output for details.
    at org.apache.tools.ant.taskdefs.Javac.compile(Javac.java:933)
    at org.apache.tools.ant.taskdefs.Javac.execute(Javac.java:757)
    at org.apache.jasper.compiler.Compiler.generateClass(Compiler.java:382)
    at org.apache.jasper.compiler.Compiler.compile(Compiler.java:472)

请把我拉出来。

谢谢。

4

1 回答 1

3

你的键应该用双引号转义",而不是单引号'。例如:

System.out.println(json.getString("site_caption"));
于 2013-04-04T11:24:31.800 回答