org.json - CookieList


Advertisements

CookieList class provides static methods to convert Cookie List to JSONObject, and vice versa. Cookie List is a sequence of name/value pairs.

Following methods are covered in the example.

  • toJSONObject(String) − Converts a cookie list text to JSONObject Object.

  • toString(JSONObject) − Converts a JSONObject to cookie list text.

Example

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));
   }
}

Output

username=Mark Den
{"username":"Mark Den"}

Useful Video Courses


Video

Reproduction in Organisms

18 Lectures 1.5 hours

Dr. Saatya Prasad

Video

Computer Organization

107 Lectures 13.5 hours

Arnab Chakraborty

Video

Basic Principles of Organic Chemistry

75 Lectures 5 hours

Revathi Ramachandran

Video

Work Area Organization for Increased Office Productivity

14 Lectures 44 mins

Zach Miller

Video

Get Organized

12 Lectures 54 mins

Prof. Paul Cline, Ed.D

Video

Organic Chemistry: How to Build People

54 Lectures 4 hours

Gilad James, PhD

Advertisements