java获取json格式中的值

先右键项目,然后点击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

posted @ 2016-12-19 23:56  Big_Foot  阅读(39155)  评论(1编辑  收藏  举报