java解析json数组

 

java解析json数组

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject; public static void main(String[] args) throws JSONException {
  String sJson = "[{'gwcxxid':'1','spsl':'2'},{'gwcxxid':'1','spsl':'2'},{'gwcxxid':'3','spsl':'4'}]";
  JSONArray jsonArray = new JSONArray(sJson);
  int iSize = jsonArray.length();
  System.out.println("Size:" + iSize);
  for (int i = 0; i < iSize; i++) {
        JSONObject jsonObj = jsonArray.getJSONObject(i);
        System.out.println("[" + i + "]gwcxxid=" + jsonObj.get("gwcxxid"));
        System.out.println("[" + i + "]spsl=" + jsonObj.get("spsl"));
        System.out.println();
    }
}
上一篇:SpringMVC Jackson 库解析 json 串属性名大小写自动转换问题


下一篇:Java解析json字符串和json数组