Code Bye

怎么样将这段字符串[["1","2","3"],["4","5","6"],["7","8","9"]]转成j

做一个从前台jquery ajax传递json到后台的功能,在js中利用JSON.stringify转换为字符串形式传递到java后端,结果如下:
[[“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);
		}

CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明怎么样将这段字符串[["1","2","3"],["4","5","6"],["7","8","9"]]转成j