1
0
Fork 0
mirror of https://github.com/ethauvin/JSON-java.git synced 2025-06-17 07:50:52 -07:00

Season's Greetings

This commit is contained in:
Douglas Crockford 2010-12-25 14:12:07 -08:00
parent f284477cff
commit 87c4b1d59d
13 changed files with 562 additions and 566 deletions

View file

@ -29,7 +29,7 @@ import java.util.Iterator;
/**
* Convert a web browser cookie list string to a JSONObject and back.
* @author JSON.org
* @version 2008-09-18
* @version 2010-12-24
*/
public class CookieList {
@ -47,15 +47,15 @@ public class CookieList {
* @throws JSONException
*/
public static JSONObject toJSONObject(String string) throws JSONException {
JSONObject o = new JSONObject();
JSONObject jo = new JSONObject();
JSONTokener x = new JSONTokener(string);
while (x.more()) {
String name = Cookie.unescape(x.nextTo('='));
x.next('=');
o.put(name, Cookie.unescape(x.nextTo(';')));
jo.put(name, Cookie.unescape(x.nextTo(';')));
x.next();
}
return o;
return jo;
}
@ -64,24 +64,24 @@ public class CookieList {
* of name/value pairs. The names are separated from the values by '='.
* The pairs are separated by ';'. The characters '%', '+', '=', and ';'
* in the names and values are replaced by "%hh".
* @param o A JSONObject
* @param jo A JSONObject
* @return A cookie list string
* @throws JSONException
*/
public static String toString(JSONObject o) throws JSONException {
public static String toString(JSONObject jo) throws JSONException {
boolean b = false;
Iterator keys = o.keys();
String s;
Iterator keys = jo.keys();
String string;
StringBuffer sb = new StringBuffer();
while (keys.hasNext()) {
s = keys.next().toString();
if (!o.isNull(s)) {
string = keys.next().toString();
if (!jo.isNull(string)) {
if (b) {
sb.append(';');
}
sb.append(Cookie.escape(s));
sb.append(Cookie.escape(string));
sb.append("=");
sb.append(Cookie.escape(o.getString(s)));
sb.append(Cookie.escape(jo.getString(string)));
b = true;
}
}