org.json - Cookie
La classe Cookie fournit des méthodes statiques pour convertir le texte du cookie du navigateur Web en JSONObject, et vice versa.
Les méthodes suivantes sont couvertes dans l'exemple.
toJSONObject(String) - Convertit un texte de cookie en objet JSONObject.
toString(JSONObject) - Convertit un JSONObject en texte de cookie.
Exemple
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));
}
}
Production
{"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=/