Skip to content

Commit 449641a

Browse files
getString("null")
1 parent 87c4b1d commit 449641a

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

JSONArray.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ of this software and associated documentation files (the "Software"), to deal
7878
* </ul>
7979
8080
* @author JSON.org
81-
* @version 2010-12-24
81+
* @version 2010-12-28
8282
*/
8383
public class JSONArray {
8484

@@ -322,7 +322,8 @@ public long getLong(int index) throws JSONException {
322322
* @throws JSONException If there is no value for the index.
323323
*/
324324
public String getString(int index) throws JSONException {
325-
return get(index).toString();
325+
Object object = get(index);
326+
return object == JSONObject.NULL ? null : object.toString();
326327
}
327328

328329

JSONObject.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ of this software and associated documentation files (the "Software"), to deal
8787
* <li>Numbers may have the <code>0x-</code> <small>(hex)</small> prefix.</li>
8888
* </ul>
8989
* @author JSON.org
90-
* @version 2010-12-24
90+
* @version 2010-12-28
9191
*/
9292
public class JSONObject {
9393

@@ -627,7 +627,8 @@ 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-
return get(key).toString();
630+
Object object = get(key);
631+
return object == NULL ? null : object.toString();
631632
}
632633

633634

0 commit comments

Comments
 (0)