JSON Object:
- 以"{"開始,以"}"結尾
- 每個名稱後跟著一個":"
- 每對"名稱:值"之間用","分隔
JSON Array:
- 以"["開始,以"]"結尾
- 值之間使用","
JSON Value:
- 值本身可以是String、Number、true、false、null、Object、Array;
JSON String:
- 由雙引號包圍的任意Unicode字元集合。可以使用"反斜線(\)"來轉義。
2 | "details" : "這是JSON的值. \n 此格式比XML合適Ajax交換資料使用." |
reference:
http://blog.kkbruce.net/2011/01/json.html#.VUwO9fmqpBc
====================================
單行及多行json格式, 字串轉json的分別。
//multiple line
temp="[{'px_emp_id':'1','px_emp_name':'jean','px_emp_tel':'337','px_emp_url':''}]";
JSONArray result_arr = new JSONArray(temp);
JSONObject
result_obj = result_arr.getJSONObject(0); //Convert String to JSON Object, get
first line
// //only one
line
//
temp="{'px_emp_id':'1','px_emp_name':'jean','px_emp_tel':'337','px_emp_url':''}";
// JSONObject result_obj = new JSONObject(temp); //Convert
String to JSON Object
mTextView1.setText(result_obj.getString("px_emp_name"));
========================================
// try {// JSONObject jo;// jo = new JSONObject(myCamera);// Collection<JSONObject> items = new ArrayList<JSONObject>();// //// JSONObject item1 = new JSONObject();//// item1.put("CameraName", "New Camera");//// item1.put("CameraID", "PXCAM1_");//// items.add(item1);// //// jo.put("aoColumnDefs", new JSONArray(items));//// Log.e("items",items.toString());// myCamera=jo.toString();//// } catch (JSONException e) {// // TODO Auto-generated catch block// e.printStackTrace();// }// Log.e("u_id"+u_id,"***");// Log.e("u_name"+u_name,"***");// Log.e("myCamera_num",""+myCamera_num);// Log.e("myCamera",""+myCamera);// Log.e("followingCamera_num",""+followingCamera_num);// Log.e("followingCamera",""+followingCamera); Log.e("======================","======================");
// JSONArray result_arr = null; // try { // result_arr = new JSONArray(myCamera); // Log.e("getJSONObject(0).getString(CameraName)",""+result_arr.getJSONObject(0).getString("CameraName").toString()); // Log.e("getJSONObject(0).getString(CameraName)",""+result_arr.getJSONObject(0).getString("CameraID").toString()); // Log.e("getJSONObject(1).getString(CameraName)",""+result_arr.getJSONObject(1).getString("CameraName").toString()); // Log.e("getJSONObject(1).getString(CameraName)",""+result_arr.getJSONObject(1).getString("CameraID").toString()); // } catch (JSONException e1) { // // TODO Auto-generated catch block // e1.printStackTrace(); // }
沒有留言:
張貼留言