1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
private String TAG = "TestJson"; //xx 这个 calendar 是key,冒号后面的内容是value,而这个value也是一个jsonobject, String xx = "{calendar :{ DataTable:[ { W_TYPE:'合同订立'," + "W_ACTIVITYNAME:'采购合同1,由人力资源部许某承办'," + "W_URL:'http://192.168.51.99/.aspx?TaskID=47eb4557-64fb-462f-810e',W_USER:'李永'}]}}"; //yy 这个DataTable是key,冒号后面的内容是value,而这个value是一个jsonarray,用【】表示 //同时,后面也可以是string,boolean,等。 //[]里面又是一个jsonobject, key是W_XXX,后面的value是string类型 String yy = "{ DataTable:[ { W_TYPE:'合同订立'," + "W_ACTIVITYNAME:'采购合同1,由人力资源部许某承办'," + "W_URL:'http://192.168.51.99/.aspx?TaskID=47eb4557-64fb-462f-810e',W_USER:'李永'}]}"; List W_TYPE = new ArrayList(); List W_ACTIVITYNAME = new ArrayList(); List W_URL = new ArrayList(); List W_USER = new ArrayList(); @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); testKeyValue() ; print(); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; } private void readJson() { try { //calendar 是key值,后面是value,一个JSONArray对象 JSONObject jsonObject = new JSONObject(xx).getJSONObject("calendar"); JSONArray array = jsonObject.getJSONArray("DataTable"); for (int i=0; i