所以,我的hean敲打了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)
请把我拖出来。
感谢。
答案 0 :(得分:3)
您的密钥应使用双引号"
进行转义,而非单引号'
。 E.g:
System.out.println(json.getString("site_caption"));