Skip to content
New issue

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

Added parse option JKParseOptionNormalizeOnNull #70

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

rabc
Copy link

@rabc rabc commented Feb 7, 2012

Added parse option JKParseOptionNormalizeOnNull to use an empty string
instead of NSNull class on null value.

A client's API return a JSON with 'null' values on server error, so to avoid app crashes while expecting a string, I'm using this new flag.

Added parse option JKParseOptionNormalizeOnNull to use an empty string
instead of NSNull class on `null` value.
@x2on
Copy link

x2on commented Apr 13, 2012

Nice would be if the value could also be nil instead an Empty String.

@rabc
Copy link
Author

rabc commented Apr 13, 2012

NSDictionary doesn't accept nil as value. It's only nil when key doesn't exist, so JSONKit would have to ignore the key and it could lead to more app crashes.

@zadr
Copy link

zadr commented Apr 13, 2012

Why assume that a string is the proper thing to return? If code is expecting a dictionary or a number and gets a string, bad things happen. What if the response is an empty string?

NSNull is explicit about being NULL. An empty string is not.

@rabc
Copy link
Author

rabc commented Apr 13, 2012

If it's an empty string, it will be an empty string. This pull request doesn't enforce use the new way, just add an extra flag.

NSNull could lead to troubles if you don't have control over the JSON you're using (that's my case, as I told in pull request comment).

@sbooth
Copy link

sbooth commented Apr 13, 2012

I agree with zadr- I don't see how replacing NSNull instances with empty strings could be construed as correct behavior. Obviously runtime errors arise by sending messages to NSNull that it doesn't respond to. If a programmer was expecting an NSDictionary and got NSString it probably wouldn't work either. t think it would be better just to post-process your JSON and remove the NSNulls.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants