Skip to content

Commit d230fd0

Browse files
author
Marcus Longmuir
committed
Added RawJSON to allow known JSON strings to be inserted without quotes.
1 parent b883a84 commit d230fd0

2 files changed

Lines changed: 71 additions & 0 deletions

File tree

JSONObject.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1459,6 +1459,9 @@ public static String valueToString(Object value) throws JSONException {
14591459
if (value.getClass().isArray()) {
14601460
return new JSONArray(value).toString();
14611461
}
1462+
if (value instanceof RawJSON) {
1463+
return value.toString();
1464+
}
14621465
return quote(value.toString());
14631466
}
14641467

RawJSON.java

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/*
2+
*
3+
*/
4+
package org.json;
5+
/**
6+
* The Class RawJSON.
7+
* @author marcuslongmuir
8+
* @version $Revision: 1.0 $
9+
*/
10+
public class RawJSON {
11+
12+
/** The raw json. */
13+
String rawJSON = null;
14+
public Object data = null;
15+
16+
/**
17+
* Instantiates a new raw json.
18+
*
19+
* @param string the string
20+
*/
21+
public RawJSON(String string){
22+
this.rawJSON = string;
23+
}
24+
25+
/**
26+
* Constructor for RawJSON.
27+
* @param string1 String
28+
* @param object Object
29+
*/
30+
public RawJSON(String string1, Object object){
31+
this.rawJSON = string1;
32+
this.data = object;
33+
}
34+
35+
/**
36+
* Sets the string.
37+
*
38+
* @param toSet the new string
39+
*/
40+
public void setString(String toSet){
41+
this.rawJSON = toSet;
42+
}
43+
44+
/**
45+
* Clone other raw json.
46+
*
47+
* @param other the other
48+
*/
49+
public void cloneOtherRawJSON(RawJSON other){
50+
this.rawJSON = other.rawJSON;
51+
}
52+
53+
/**
54+
* Clone json object.
55+
*
56+
* @param obj the obj
57+
*/
58+
public void cloneJSONObject(JSONObject obj){
59+
this.rawJSON = obj.toString();
60+
}
61+
62+
/* (non-Javadoc)
63+
* @see java.lang.Object#toString()
64+
*/
65+
public String toString(){
66+
return this.rawJSON;
67+
}
68+
}

0 commit comments

Comments
 (0)