import java.io.PrintWriter;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import net.sf.json.JSONObject;
.......
...... java code
public void methodName() {
HttpServletResponse response = getResponse();
response.setContentType("text/json; charset=UTF-8");
response.setCharacterEncoding("UTF-8");
PrintWriter out = null;
try {
out = response.getWriter();
} catch (IOException e) {
logger.error(e.getMessage(),e);
}
String json = "{key:\"value\"}";
JSONObject jsonObject = JSONObject.fromObject(json);
out.print(jsonObject);
}
.......
...... java code
ps: json处理应用的jar包为[json-lib-2.1-jdk15.jar]