//生成一個JsonArray

JSONArray JArray=newJSONArray();

 

      //生成一個JSONObject

      JSONObject jsonObj =new JSONObject();

 

就這麼簡單....

 

 

//將資料put進去JsonObject

 

      jsonObj.put("Handsome","yes");

 

      jsonObj.put("MyName","Deyu");

 

//將JsonObject put進去JsonArray

 

JArray.put(jsonObj);

 

 

    Log.e("你弄的JsonArray",jArray.toString());  //你弄出的JSonArray轉成字串

 

/* 弄出來的 JsonArray應該大概長這樣吧

[{"Handsome": "yes" ,"MyName":"Deyu"}]

 

*/

 

假如put兩個jsonObject 大概會變成這樣

 

JArray.put(jsonObj);

 

JArray.put(jsonObj);

 

 

 

 

 

    Log.e("你弄的JsonArray",jArray.toString());  //你弄出的JSonArray轉成字串

 

 

/* 弄出來的 JsonArray應該大概長這樣吧

 

[{"Handsome": "yes" ,"MyName":"Deyu"},{"Handsome": "yes" ,"MyName":"Deyu"}]

 

 

 

*/

 

 

 

 

arrow
arrow
    全站熱搜

    Deyu 發表在 痞客邦 留言(0) 人氣()