做一个从前台jquery ajax传递json到后台的功能,在js中利用JSON.stringify转换为字符串形式传递到java后端,结果如下:
[[“1″,”2″,”3”],[“4″,”5″,”6”],[“7″,”8″,”9”]]
问一下怎么样将以上字符串再转成可供java使用的json或二维数组呢?
[[“1″,”2″,”3”],[“4″,”5″,”6”],[“7″,”8″,”9”]]
问一下怎么样将以上字符串再转成可供java使用的json或二维数组呢?
解决方案
20
例如用Json-lib的话:
String string = "[["1","2","3"],["4","5","6"],["7","8","9"]]"; Object[] array = (Object[]) JSONArray.toArray(JSONArray.fromObject(string)); Integer[][] result = new Integer[array.length][]; for (int i = 0; i < array.length; i++) { result[i] = (Integer[]) JSONArray.toArray(JSONArray.fromObject(array[i]), Integer.class); }