JSONObject = {}
JSONArray = []
{ "id":"1", "title":"52週階梯式存錢法", "note": [ "step 1:開啟附件檔案。", "step 2:設定起始金額為10元,輸入完後下方會自動產生每週儲蓄金額。", "step 3:將此表印出並貼在手帳、行事曆、桌曆上,當週儲蓄完就填上日期。", "step 4:若確實執行,年底就會有一筆獎勵金嘍!" ], "name":"test01" }
使用方式如下:
{ ... String str = ""; // 此範例預設str為上述JSON字串 JSONObject jsonObject = new JSONObject(str); String strId = jsonObject.getString("id"); // 取得id的文字。 String strTitle = jsonObject.getString("title"); // 取得title的文字。 String strName = jsonObject.getString("name"); // 取得title的文字。 JSONArray jsonArray = new JSONArray(jsonObject.getString("note")); // 取得note的陣列。 String[] strNote; for(int i = 0; i < jsonArray.length(); i++) { strNote[i] = jsonArray.getString(i); } ... }
沒有留言:
張貼留言