0
我是新手。我使用httpservlet响应从struts动作发送数据。我应该怎么做才能在javascript中检索这个值来将这些值设置为html元素。如何通过解析json数据来检索从javascript中的struts动作发送的值
使用Struts动作和httpservlet对象写入响应。
Gson gson = new Gson(); //using gson-2.3.1.jar
//log.debug("Printing values ... ");
//log.debug(gson.toJson(languagesResponse.getLanguages()));
response.setContentType("application/json");
// Get the printwriter object from response to write the required json object to the output stream
PrintWriter out = response.getWriter();
// Assuming your json object is **jsonObject**, perform the following, it will return your json object
out.print(gson.toJson(languagesResponse.getLanguages()));
out.flush();
让JSON返回值:
[{ “stringCode”: “默认”, “numberCode”:0, “__ hashCodeCalc”:假},{ “stringCode”: “EN_US” ,“numberCode”:1,“__ hashCodeCalc”:false}]
我想为javascript elemtent获取此值。
我知道它的客户端代码来处理,但我不知道我应该怎么在客户端获得响应数据.. – k00989 2014-12-19 06:47:13
你有没有检查我提供的链接?那些应该有相当广泛的材料来处理你所问的所有问题。 – 2014-12-19 06:48:22