java - 在 javascript 或 Jquery 中解析 JSONObject

标签 java jquery json

嗨 friend 们,我在 Ajax 方法中有一个 java.util.Map 对象,如下所示..

Map<String,List<String>> sm = new TreeMap<>();

    List<String> str = new ArrayList<String>();
    str.add("val1");
    str.add("val2");
    str.add("val3");
    str.add("val4");

    sm.put("shift1", str);
    sm.put("shift2", str);
    sm.put("shift3", str);
    sm.put("shift4", str);

    JSONObject json = new JSONObject(sm);

    response.getWriter().print(json);

运行时 map 元素会增加或减少 根据 map 元素我必须生成表格

这是 Ajax 调用..我不知道如何解析该 Map 对象并在 JavaScript 中动态生成表格。

请告诉我怎么做。

最佳答案

我只是回答你的问题。我不懂java,也不明白你上面给出的细节。如果我错了,我很抱歉,请忽略它。

将字符串解析为对象

In the jQuery, $.parseJSON(string);

In js, JSON.parse(string);

我希望这对你有帮助。谢谢。

关于java - 在 javascript 或 Jquery 中解析 JSONObject,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14954498/

相关文章:

c++ - 在glTF文件中跨步的属性?

java - 子集合未在 hibernate 状态下通过级联全部进行更新?

java - 将包传递给设置为单任务的 Activity

javascript - jeditable - 在运行时禁用它

javascript - jQuery 删除/添加类只能工作一次

c# - 如何将 javascript 中的 JSON 数组传递到我的代码隐藏文件

php - 基于存储在 Json 文件中的元数据创建数据库模式的 PHP 项目的名称?

java - 如何在处理中使用 libfreenect java 包装器

java - Libgdx 非缩放全屏

javascript - 如何让灯箱滚动但背景不滚动