嗨 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/