日期:2014-05-16 浏览次数:20594 次
JSON具有以下这些形式:
对象是一个无序的“‘名称/值’对”集合。一个对象以“{”(左括号)开始,“}”(右括号)结束。每个“名称”后跟一个“:”(冒号);“‘名称/值’ 对”之间使用“,”(逗号)分隔。

数组是值(value)的有序集合。一个数组以“[”(左中括号)开始,“]”(右中括号)结束。值之间使用“,”(逗号)分隔。

值(value)可以是双引号括起来的字符串(string)、数值(number)、true、false、 null、对象(object)或者数组(array)。这些结构可以嵌套。

opt、optBoolean、optDouble、optInt、optLong、optString、optJSONArray、optJSONObject get、getBoolean、getDouble、getInt、getLong、getString、getJSONArray、getJSONObject
    private String createJson() throws JSONException {
     JSONObject jsonObject = new JSONObject();
     jsonObject.put ("intKey" , 123);
     jsonObject.put ("doubleKey" , 10.1);
     jsonObject.put ("longKey" , 666666666);
     jsonObject.put ("stringKey" , "lalala" );
     jsonObject.put ("booleanKey" , true);
     
     JSONArray jsonArray = new JSONArray();
     jsonArray.put (0, 111);
     jsonArray.put("second");
     jsonObject.put ("arrayKey" , jsonArray);
     
     JSONObject innerJsonObject = new JSONObject();
     innerJsonObject.put ("innerStr" , "inner" );
     jsonObject.put ("innerObjectKey" , innerJsonObject);
     
     
     Log.e("Json" , jsonObject.toString());
     
     return jsonObject.toString();
     }    private void pareJson(String jsonStr) throws JSONException {
     JSONObject jsonObject = new JSONObject(jsonStr);
     int intValue       = jsonObjec