龙盟编程博客 | 无障碍搜索 | 云盘搜索神器
快速搜索
主页 > web编程 > Javascript编程 >

对比分析json及XML(9)

时间:2014-12-03 03:00来源:网络整理 作者:网络 点击:
分享到:
复制代码 代码如下: private String createJson() throws JSONException { JSONObject jsonObject = new JSONObject(); jsonObject.put("intKey", 123); jsonObject.put("doubleKey", 10.1); jsonObject.put

复制代码 代码如下:

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();
}

  其输出结果如下所示:

精彩图集

赞助商链接