解析JSONArray

//[{"k":"20","na":"30"},{"k":"50","na":"60"},{"k":"10","na":"40"},{"k":"30","na":"80"}]
String json = this.getResources().getString(R.string.json);


try {
JSONArray array = new JSONArray(json);
int[] n = new int[array.length()];
for (int i = 0; i < array.length(); i++) {
JSONObject jsonObject = array.getJSONObject(i);
n[i] = jsonObject.getInt("k");
Log.i("ceshi", n[i] + "");
}


} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

你可能感兴趣的:(JsonArray)