Json

如何创建JSON?
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();
}

其输出结果如下所示:

posted @ 2016-07-08 15:40  moon0521  阅读(60)  评论(0)    收藏  举报