📅  最后修改于: 2020-11-12 05:09:13             🧑  作者: Mango
JSONObject类是键-值对的无序集合。它提供了通过键访问值和放置值的方法。支持以下类型-
布尔型
JSONArray
JSONObject
数
串
JSONObject.NULL对象
import org.json.JSONArray;
import org.json.JSONObject;
public class JSONDemo {
public static void main(String[] args) {
JSONObject jsonObject = new JSONObject();
jsonObject.put("Name", "Robert");
jsonObject.put("ID", 1);
jsonObject.put("Fees", new Double(1000.21));
jsonObject.put("Active", new Boolean(true));
jsonObject.put("Other Details", JSONObject.NULL);
JSONArray list = new JSONArray();
list.put("foo");
list.put(new Integer(100));
jsonObject.put("list",list);
System.out.println(jsonObject);
}
}
{"Active":true,"Other Details":null,"ID":1,"Fees":1000.21,"list":["foo",100],"Name":"Robert"}