- org.json 教程
- org.json - 主页
- org.json - 概述
- org.json - 环境设置
- CSV 示例
- org.json-CDL
- Cookie 示例
- org.json - Cookie
- org.json - CookieList
- HTTP 标头示例
- org.json - HTTP
- JSON 示例
- org.json - JSONArray
- org.json - JSONML
- org.json - JSONObject
- org.json - JSONStringer
- 属性示例
- org.json - 属性
- XML 示例
- org.json - XML
- 异常处理
- org.json - JSON异常处理
- org.json 有用资源
- org.json - 快速指南
- org.json - 有用的资源
- org.json - 讨论
org.json - CookieList
CookieList 类提供静态方法将 Cookie List 转换为 JSONObject,反之亦然。Cookie 列表是名称/值对的序列。
示例中涵盖了以下方法。
toJSONObject(String) - 将 cookie 列表文本转换为 JSONObject 对象。
toString(JSONObject) - 将 JSONObject 转换为 cookie 列表文本。
例子
import org.json.Cookie;
import org.json.CookieList;
import org.json.JSONObject;
public class JSONDemo {
public static void main(String[] args) {
String cookie = "username = Mark Den; expires = Thu, 15 Jun 2020 12:00:00 UTC; path = /";
//Case 1: Converts Cookie String to JSONObject
JSONObject cookieJSONObject = Cookie.toJSONObject(cookie);
JSONObject cookielistJSONObject = new JSONObject();
cookielistJSONObject.put(cookieJSONObject.getString("name"),
cookieJSONObject.getString("value"));
String cookieList = CookieList.toString(cookielistJSONObject);
System.out.println(cookieList);
System.out.println(CookieList.toJSONObject(cookieList));
}
}
输出
username=Mark Den
{"username":"Mark Den"}