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

* Adds protected entrySet accessor to JSONObject

* Updates loops that request key/value pairs to use the new entrySet accessor
This commit is contained in:
John J. Aylward 2017-05-22 00:50:39 -04:00
parent fbd2be7431
commit 4f5bf16676
7 changed files with 95 additions and 88 deletions

View file

@ -1,5 +1,7 @@
package org.json;
import java.util.Map.Entry;
/*
Copyright (c) 2002 JSON.org
@ -24,8 +26,6 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
import java.util.Iterator;
/**
* Convert a web browser cookie list string to a JSONObject and back.
* @author JSON.org
@ -69,18 +69,17 @@ public class CookieList {
*/
public static String toString(JSONObject jo) throws JSONException {
boolean b = false;
Iterator<String> keys = jo.keys();
String string;
StringBuilder sb = new StringBuilder();
while (keys.hasNext()) {
string = keys.next();
if (!jo.isNull(string)) {
for (final Entry<String,?> entry : jo.entrySet()) {
final String key = entry.getKey();
final Object value = entry.getValue();
if (!JSONObject.NULL.equals(value)) {
if (b) {
sb.append(';');
}
sb.append(Cookie.escape(string));
sb.append(Cookie.escape(key));
sb.append("=");
sb.append(Cookie.escape(jo.getString(string)));
sb.append(Cookie.escape(value.toString()));
b = true;
}
}