JSONObject

JSONObject,第1张

JSONObject
package com.dxy.study_0628.study.json;

import org.json.JSONException;
import org.json.JSONObject;

import java.util.HashMap;

public class JsonStudy {
    public static void main(String[] args) {
        JSONObject zhangsan = new JSONObject();
        try {
            //添加
            zhangsan.put("name", "张三");
            zhangsan.put("age", 18.4);
            zhangsan.put("birthday", "1900-20-03");
            zhangsan.put("majar", new String[] {"哈哈","嘿嘿"});
            zhangsan.put("null", "null");
            zhangsan.put("house", false);
            System.out.println(zhangsan.toString());
        } catch (JSONException e) {
            e.printStackTrace();
        }

        HashMap zhangsan1 = new HashMap<>();

        zhangsan1.put("name", "张三");
        zhangsan1.put("age", 18.4);
        zhangsan1.put("birthday", "1900-20-03");
        zhangsan1.put("majar", new String[] {"哈哈","嘿嘿"});
        zhangsan1.put("null", null);
        zhangsan1.put("house", false);
        System.out.println(new JSONObject(zhangsan1).toString());
    }

}

https://blog.csdn.net/u012448904/article/details/84292821

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zaji/5612789.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-15
下一篇 2022-12-15

发表评论

登录后才能评论

评论列表(0条)

保存