| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
package org.json.simple; |
| 6 |
|
|
| 7 |
|
import java.io.IOException; |
| 8 |
|
import java.io.StringWriter; |
| 9 |
|
import java.io.Writer; |
| 10 |
|
import java.util.HashMap; |
| 11 |
|
import java.util.Iterator; |
| 12 |
|
import java.util.Map; |
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
|
| 17 |
|
|
| 18 |
|
@author |
| 19 |
|
|
| |
|
| 0% |
Uncovered Elements: 53 (53) |
Complexity: 14 |
Complexity Density: 0.39 |
|
| 20 |
|
public class JSONObject extends HashMap |
| 21 |
|
implements Map, JSONAware, JSONStreamAware |
| 22 |
|
{ |
| 23 |
|
|
| 24 |
|
private static final long serialVersionUID = -503443796854799292L; |
| 25 |
|
|
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 26 |
0 |
public JSONObject()... |
| 27 |
|
{ |
| 28 |
0 |
super(); |
| 29 |
|
} |
| 30 |
|
|
| 31 |
|
|
| 32 |
|
|
| 33 |
|
|
| 34 |
|
|
| 35 |
|
@param |
| 36 |
|
|
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 37 |
0 |
public JSONObject(Map map)... |
| 38 |
|
{ |
| 39 |
0 |
super(map); |
| 40 |
|
} |
| 41 |
|
|
| 42 |
|
|
| 43 |
|
|
| 44 |
|
|
| 45 |
|
|
| 46 |
|
|
| 47 |
|
@see |
| 48 |
|
|
| 49 |
|
@param |
| 50 |
|
@param |
| 51 |
|
|
| |
|
| 0% |
Uncovered Elements: 23 (23) |
Complexity: 4 |
Complexity Density: 0.24 |
|
| 52 |
0 |
public static void writeJSONString(Map map, Writer out) throws IOException... |
| 53 |
|
{ |
| 54 |
0 |
if (map == null) |
| 55 |
|
{ |
| 56 |
0 |
out.write("null"); |
| 57 |
0 |
return; |
| 58 |
|
} |
| 59 |
|
|
| 60 |
0 |
boolean first = true; |
| 61 |
0 |
Iterator iter = map.entrySet().iterator(); |
| 62 |
|
|
| 63 |
0 |
out.write('{'); |
| 64 |
0 |
while (iter.hasNext()) |
| 65 |
|
{ |
| 66 |
0 |
if (first) |
| 67 |
0 |
first = false; |
| 68 |
|
else |
| 69 |
0 |
out.write(','); |
| 70 |
0 |
Map.Entry entry = (Map.Entry) iter.next(); |
| 71 |
0 |
out.write('\"'); |
| 72 |
0 |
out.write(escape(String.valueOf(entry.getKey()))); |
| 73 |
0 |
out.write('\"'); |
| 74 |
0 |
out.write(':'); |
| 75 |
0 |
JSONValue.writeJSONString(entry.getValue(), out); |
| 76 |
|
} |
| 77 |
0 |
out.write('}'); |
| 78 |
|
} |
| 79 |
|
|
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 80 |
0 |
public void writeJSONString(Writer out) throws IOException... |
| 81 |
|
{ |
| 82 |
0 |
writeJSONString(this, out); |
| 83 |
|
} |
| 84 |
|
|
| 85 |
|
|
| 86 |
|
|
| 87 |
|
|
| 88 |
|
|
| 89 |
|
|
| 90 |
|
@see |
| 91 |
|
|
| 92 |
|
@param |
| 93 |
|
@return |
| 94 |
|
|
| |
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 2 |
Complexity Density: 0.4 |
|
| 95 |
0 |
public static String toJSONString(Map map)... |
| 96 |
|
{ |
| 97 |
0 |
final StringWriter writer = new StringWriter(); |
| 98 |
|
|
| 99 |
0 |
try |
| 100 |
|
{ |
| 101 |
0 |
writeJSONString(map, writer); |
| 102 |
0 |
return writer.toString(); |
| 103 |
|
} catch (IOException e) |
| 104 |
|
{ |
| 105 |
|
|
| 106 |
0 |
throw new RuntimeException(e); |
| 107 |
|
} |
| 108 |
|
} |
| 109 |
|
|
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 110 |
0 |
public String toJSONString()... |
| 111 |
|
{ |
| 112 |
0 |
return toJSONString(this); |
| 113 |
|
} |
| 114 |
|
|
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 115 |
0 |
public String toString()... |
| 116 |
|
{ |
| 117 |
0 |
return toJSONString(); |
| 118 |
|
} |
| 119 |
|
|
| |
|
| 0% |
Uncovered Elements: 10 (10) |
Complexity: 2 |
Complexity Density: 0.25 |
|
| 120 |
0 |
public static String toString(String key, Object value)... |
| 121 |
|
{ |
| 122 |
0 |
StringBuffer sb = new StringBuffer(); |
| 123 |
0 |
sb.append('\"'); |
| 124 |
0 |
if (key == null) |
| 125 |
0 |
sb.append("null"); |
| 126 |
|
else |
| 127 |
0 |
JSONValue.escape(key, sb); |
| 128 |
0 |
sb.append('\"').append(':'); |
| 129 |
|
|
| 130 |
0 |
sb.append(JSONValue.toJSONString(value)); |
| 131 |
|
|
| 132 |
0 |
return sb.toString(); |
| 133 |
|
} |
| 134 |
|
|
| 135 |
|
|
| 136 |
|
|
| 137 |
|
|
| 138 |
|
|
| 139 |
|
|
| 140 |
|
@see |
| 141 |
|
|
| 142 |
|
@param |
| 143 |
|
@return |
| 144 |
|
|
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 145 |
0 |
public static String escape(String s)... |
| 146 |
|
{ |
| 147 |
0 |
return JSONValue.escape(s); |
| 148 |
|
} |
| 149 |
|
} |