// Decompiled by Jad v1.5.8e. Copyright 2001 Pavel Kouznetsov. // Jad home page: http://www.geocities.com/kpdus/jad.html // Decompiler options: braces fieldsfirst space lnc package org.apache.oltu.oauth2.common.utils; import java.util.HashMap; import java.util.Iterator; import java.util.Map; import java.util.Set; import org.json.JSONArray; import org.json.JSONStringer; import org.json.JSONTokener; import org.json.JSONWriter; public final class JSONUtils { public JSONUtils() { } public static String buildJSON(Map map) { JSONStringer jsonstringer = new JSONStringer(); jsonstringer.object(); map = map.entrySet().iterator(); do { if (!map.hasNext()) { break; } java.util.Map.Entry entry = (java.util.Map.Entry)map.next(); if (entry.getKey() != null && !"".equals(entry.getKey()) && entry.getValue() != null && !"".equals(entry.getValue())) { jsonstringer.key((String)entry.getKey()).value(entry.getValue()); } } while (true); return jsonstringer.endObject().toString(); } public static Map parseJSON(String s) { HashMap hashmap; JSONTokener jsontokener; hashmap = new HashMap(); jsontokener = new JSONTokener(s); if (jsontokener.nextClean() != '{') { throw new IllegalArgumentException(String.format("String '%s' is not a valid JSON object representation, a JSON object text must begin with '{'", new Object[] { s })); } goto _L1 _L8: jsontokener.back(); _L1: jsontokener.nextClean(); JVM INSTR lookupswitch 2: default 84 // 0: 191 // 125: 316; goto _L2 _L3 _L4 _L2: jsontokener.back(); String s1 = jsontokener.nextValue().toString(); int i = jsontokener.nextClean(); Object obj1; if (i == 61) { if (jsontokener.next() != '>') { jsontokener.back(); } } else if (i != 58) { throw new IllegalArgumentException(String.format("String '%s' is not a valid JSON object representation, expected a ':' after the key '%s'", new Object[] { s, s1 })); } obj1 = jsontokener.nextValue(); if (obj1 != null) { Object obj = obj1; if (obj1 instanceof JSONArray) { obj1 = (JSONArray)obj1; obj = ((Object) (new Object[((JSONArray) (obj1)).length()])); for (i = 0; i < ((JSONArray) (obj1)).length(); i++) { obj[i] = ((JSONArray) (obj1)).get(i); } } hashmap.put(s1, obj); } goto _L5 _L3: throw new IllegalArgumentException(String.format("String '%s' is not a valid JSON object representation, a JSON object text must end with '}'", new Object[] { s })); _L5: jsontokener.nextClean(); JVM INSTR lookupswitch 3: default 296 // 44: 306 // 59: 306 // 125: 316; goto _L6 _L7 _L7 _L4 _L6: throw new IllegalArgumentException("Expected a ',' or '}'"); _L7: if (jsontokener.nextClean() != '}') goto _L8; else goto _L4 _L4: return hashmap; } }