java解析json数组:需要添加一个jar包,自己搜索即可
import
import
import
public 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
0 ; i < iSize; i++) { JSONObject jsonObj = jsonArray.getJSONObject(i); System.out.println( "[" + i + "]gwcxxid=" + jsonObj.get( "gwcxxid" )); System.out.println( "[" + i + "]spsl="
"spsl" )); System.out.println(); } } |