I want to read/write real string value "null"(as name anything), but string "null"(any of different 16 combinations, if use any character case: "NULL", "nUll", "NulL", ...) converts to null (JSONNull object).
Example code:
public class Test_JSON extends TestCase {
public void test() {
final Map map = new HashMap();
map.put("key", "null");
JSONObject jsonObject = new JSONObject(map);
System.out.println("JSON Object from Map:");
System.out.println(jsonObject.toString(4));
String json = "{key1:\"null\"}";
System.out.println();
System.out.println("JSON String(source):");
System.out.println(json);
jsonObject = new JSONObject(json);
System.out.println();
System.out.println("JSON Object:");
System.out.println(jsonObject.toString(4));
System.out.println();
System.out.println("Real object:");
System.out.println(jsonObject.get("key1").getClass());
}
}
Output:
JSON Object from Map:
{"key": null}
JSON String(source):
{key1:"null"}
JSON Object:
{"key1": null}
Real object:
class net.sf.json.JSONNull
Is this correct behaviour?
Thanks
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Alexey,
The string [null] or any permutation with lower/upper case will case the value to be converted to a JSONNull as you describe.
Have you tried the following string "'null'" or even "\"null\""?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hello
I want to read/write real string value "null"(as name anything), but string "null"(any of different 16 combinations, if use any character case: "NULL", "nUll", "NulL", ...) converts to null (JSONNull object).
Example code:
public class Test_JSON extends TestCase {
public void test() {
final Map map = new HashMap();
map.put("key", "null");
JSONObject jsonObject = new JSONObject(map);
System.out.println("JSON Object from Map:");
System.out.println(jsonObject.toString(4));
String json = "{key1:\"null\"}";
System.out.println();
System.out.println("JSON String(source):");
System.out.println(json);
jsonObject = new JSONObject(json);
System.out.println();
System.out.println("JSON Object:");
System.out.println(jsonObject.toString(4));
System.out.println();
System.out.println("Real object:");
System.out.println(jsonObject.get("key1").getClass());
}
}
Output:
JSON Object from Map:
{"key": null}
JSON String(source):
{key1:"null"}
JSON Object:
{"key1": null}
Real object:
class net.sf.json.JSONNull
Is this correct behaviour?
Thanks
Alexey,
The string [null] or any permutation with lower/upper case will case the value to be converted to a JSONNull as you describe.
Have you tried the following string "'null'" or even "\"null\""?