Node Director
Static Public Member Functions | List of all members
org.json.Cookie Class Reference

Convert a web browser cookie specification to a JSONObject and back. More...

Static Public Member Functions

static String escape (String string)
 Produce a copy of a string in which the characters '+', '', '=', ';' and control characters are replaced with "%hh".
static JSONObject toJSONObject (String string) throws ParseException
 Convert a cookie specification string into a JSONObject.
static String toString (JSONObject o)
 Convert a JSONObject into a cookie specification string.

Detailed Description

Convert a web browser cookie specification to a JSONObject and back.

JSON and Cookies are both notations for name/value pairs.

Author
JSON.org
Version
0.1

Member Function Documentation

static String org.json.Cookie.escape ( String  string)
static

Produce a copy of a string in which the characters '+', '', '=', ';' and control characters are replaced with "%hh".

This is a gentle form of URL encoding, attempting to cause as little distortion to the string as possible. The characters '=' and ';' are meta characters in cookies. By convention, they are escaped using the URL-encoding. This is only a convention, not a standard. Often, cookies are expected to have encoded values. We encode '=' and ';' because we must. We encode '' and '+' because they are meta characters in URL encoding.

Parameters
stringThe source string.
Returns
The escaped result.

Referenced by org.json.CookieList.toString(), and org.json.Cookie.toString().

static JSONObject org.json.Cookie.toJSONObject ( String  string) throws ParseException
static

Convert a cookie specification string into a JSONObject.

The string will contain a name value pair separated by '='. The name and the value will be unescaped, possibly converting '+' and '' sequences. The cookie properties may follow, separated by ';', also represented as name=value (except the secure property, which does not have a value). The name will be stored under the key "name", and the value will be stored under the key "value". This method does not do checking or validation of the parameters. It only converts the cookie string into a JSONObject.

Parameters
stringThe cookie specification string.
Returns
A JSONObject containing "name", "value", and possibly other members.
Exceptions
ParseException

References org.json.JSONTokener.more(), org.json.JSONTokener.next(), org.json.JSONTokener.nextTo(), org.json.JSONObject.put(), org.json.JSONTokener.syntaxError(), and org.json.JSONTokener.unescape().

Referenced by org.json.Test.main().

static String org.json.Cookie.toString ( JSONObject  o)
static

Convert a JSONObject into a cookie specification string.

The JSONObject must contain "name" and "value" members. If the JSONObject contains "expires", "domain", "path", or "secure" members, they will be appended to the cookie specification string. All other members are ignored.

Parameters
oA JSONObject
Returns
A cookie specification string

References org.json.Cookie.escape(), org.json.JSONObject.getString(), org.json.JSONObject.has(), and org.json.JSONObject.optBoolean().

Referenced by org.json.Test.main().


The documentation for this class was generated from the following file: