Org-json-cookie
提供:Dev Guides
org.json-クッキー
Cookieクラスは、WebブラウザーのCookieテキストをJSONObjectに、またはその逆に変換する静的メソッドを提供します。
この例では、次の方法について説明します。
- * toJSONObject(String)*-CookieテキストをJSONObjectオブジェクトに変換します。
- * toString(JSONObject)*-JSONObjectをCookieテキストに変換します。
例
import org.json.Cookie;
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 jsonObject = Cookie.toJSONObject(cookie);
System.out.println(jsonObject);
//Case 2: Converts JSONObject to Cookie String
System.out.println(Cookie.toString(jsonObject));
}
}
出力
{"path":"/","expires":"Thu, 15 Jun 2020 12:00:00 UTC","name":"username","value":"Mark Den"}
username=Mark Den;expires=Thu, 15 Jun 2020 12:00:00 UTC;path=/