File tree Expand file tree Collapse file tree 2 files changed +15
-0
lines changed
Expand file tree Collapse file tree 2 files changed +15
-0
lines changed Original file line number Diff line number Diff line change @@ -627,6 +627,9 @@ public static String[] getNames(Object object) {
627627 * @throws JSONException if the key is not found.
628628 */
629629 public String getString (String key ) throws JSONException {
630+ if (isNull (key )){
631+ return null ;
632+ }
630633 return get (key ).toString ();
631634 }
632635
Original file line number Diff line number Diff line change @@ -67,6 +67,18 @@ public void testXML() throws Exception {
6767 assertEquals ("<test><blank/><empty/></test>" , XML .toString (j ));
6868 }
6969
70+ public void testNull () throws Exception {
71+ JSONObject j ;
72+
73+ j = new JSONObject ("{\" message\" :\" null\" }" );
74+ assertFalse (j .isNull ("message" ));
75+ assertEquals ("null" , j .getString ("message" ));
76+
77+ j = new JSONObject ("{\" message\" :null}" );
78+ assertTrue (j .isNull ("message" ));
79+ assertEquals (null , j .getString ("message" ));
80+ }
81+
7082 public void testJSON () throws Exception {
7183 Iterator it ;
7284 JSONArray a ;
You can’t perform that action at this time.
0 commit comments