We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
A json string, maybe the user's name just is null:
{ "name": "null", "mobile": "123" }
Parsing:
JSONObject json = JSONObject.fromObject(jsonStr); System.out.println(json.getString("name"));
Output:
“null”
But expected:
null
I read the source code, the string null is considered a JSON, So quote are added to both ends of the string null.
if( quoted && v instanceof String && (JSONUtils.mayBeJSON( (String) v ) || JSONUtils.isFunction( v ))){ v = JSONUtils.DOUBLE_QUOTE + v + JSONUtils.DOUBLE_QUOTE; } public static boolean mayBeJSON( String string ) { return string != null && ("null".equals( string ) || (string.startsWith( "[" ) && string.endsWith( "]" )) || (string.startsWith( "{" ) && string.endsWith( "}" ))); }
If this is a bug, I am happy to fix it.
The text was updated successfully, but these errors were encountered:
hey, if you expected the value is null, then the null of json string should not be wrapped by quotes, instead as follows:
{ "name": null, "mobile": "123" }
and when get the value of "name", we should use json.get("name") rather than json.getString("name")
json.get("name")
json.getString("name")
Sorry, something went wrong.
No branches or pull requests
A json string, maybe the user's name just is null:
Parsing:
Output:
But expected:
I read the source code, the string null is considered a JSON, So quote are added to both ends of the string null.
If this is a bug, I am happy to fix it.
The text was updated successfully, but these errors were encountered: