本文实例讲述了java实现二维数组转json的方法。分享给大家供大家参考,具体如下:
package tsets; public class erweitojson { public static void main(string[] args) { string[][] bloglist = { {"2008/07/07", "netbeans new and cool", "tim boudreau"}, {"2008/07/07", "netbeans mobility", "ada li"}, {"2008/07/07", "creating web 2.0 rich internet applications", "michael li"}, {"2008/07/08", "ajax and jsf", "ada li"}, {"2008/07/09", "ruby on rails in the enterprise", "liang ye"}, {"2008/07/09", "beans binding and the swing application framework", "joey shen"} }; stringbuffer sb = new stringbuffer(); boolean first = true; sb.append("["); for (int i = 0; i < bloglist.length; i++) { string[] blogitem = bloglist[i]; if (!first) { sb.append(","); } sb.append("{"); sb.append("postdate: '" + blogitem[0] + "', "); sb.append("title: '" + blogitem[1] + "', "); sb.append("author: '" + blogitem[2] + "' "); sb.append("}"); first = false; } sb.append("]"); system.out.println(sb.tostring()); } }
运行结果:
复制代码 代码如下:
[{postdate: '2008/07/07', title: 'netbeans new and cool', author: 'tim boudreau' },{postdate: '2008/07/07', title: 'netbeans mobility', author: 'ada li' },{postdate: '2008/07/07', title: 'creating web 2.0 rich internet applications', author: 'michael li' },{postdate: '2008/07/08', title: 'ajax and jsf', author: 'ada li' },{postdate: '2008/07/09', title: 'ruby on rails in the enterprise', author: 'liang ye' },{postdate: '2008/07/09', title: 'beans binding and the swing application framework', author: 'joey shen' }]
以上就是java二维数组转json的实现方法的详细内容。
