先右键项目,然后点击properties,然后选中java Builder Path,选择add external jars,引入需要引入json.jar

package web;

import org.json.JSONArray;
import org.json.JSONException; public class josn {
public static void main(String[] args) throws JSONException {
String str = "[{'columnId':5,'columnName':'人文历史'},{'columnId':2,'columnName':'商业视野'}]}";
JSONArray jsonArray = null;
jsonArray = new JSONArray(str);
System.out.println(jsonArray.getJSONObject(1).get("columnId"));
} }

输出:

2

04-27 15:58