Home > Java > javaTutorial > Implementation method of converting Java two-dimensional array to json

Implementation method of converting Java two-dimensional array to json

黄舟
Release: 2017-10-13 10:08:22
Original
2577 people have browsed it

This article mainly introduces the method of converting two-dimensional arrays to json in java, involving java array traversal and json format data construction related operation skills. Friends in need can refer to it

The examples in this article describe the java implementation How to convert two-dimensional array to json. Share it with everyone for your reference, the details are as follows:


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: &#39;" + blogItem[0] + "&#39;, ");
   sb.append("title: &#39;" + blogItem[1] + "&#39;, ");
   sb.append("author: &#39;" + blogItem[2] + "&#39; ");
   sb.append("}");
   first = false;
  }
  sb.append("]");
  System.out.println(sb.toString());
 }
}
Copy after login

Running results:

Copy code The code is as follows:

[{postdate: &#39;2008/07/07&#39;, title: &#39;NetBeans New and Cool&#39;, author: &#39;Tim Boudreau&#39; },{postdate: &#39;2008/07/07&#39;, title: &#39;NetBeans Mobility&#39;, author: &#39;Ada Li&#39; },{postdate: &#39;2008/07/07&#39;, title: &#39;Creating Web 2.0 Rich Internet Applications&#39;, author: &#39;Michael Li&#39; },{postdate: &#39;2008/07/08&#39;, title: &#39;AJAX and JSF&#39;, author: &#39;Ada Li&#39; },{postdate: &#39;2008/07/09&#39;, title: &#39;Ruby on Rails in the Enterprise&#39;, author: &#39;Liang Ye&#39; },{postdate: &#39;2008/07/09&#39;, title: &#39;Beans Binding and the Swing Application Framework&#39;, author: &#39;Joey Shen&#39; }]
Copy after login


The above is the detailed content of Implementation method of converting Java two-dimensional array to json. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template