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

Verify json_decode was successful #53

Closed
abraham opened this issue Sep 29, 2010 · 3 comments
Closed

Verify json_decode was successful #53

abraham opened this issue Sep 29, 2010 · 3 comments
Labels

Comments

@abraham
Copy link
Owner

abraham commented Sep 29, 2010

json_decode will return null if the json is invalid. Check for it and return original content.

@katanacrimson
Copy link

Or you could use this:
http://us3.php.net/manual/en/function.json-last-error.php

@abraham
Copy link
Owner Author

abraham commented Sep 30, 2010

That is cool. Too bad it is 5.3+. I'll have have to think of how I want to deal with version specific features.

@katanacrimson
Copy link

Oh, huh. So it is, I guess I need to update my own JSON wrapper.

FWIW, you might find it useful. MIT Licensed, as well: http://github.com/OpenFlame/OpenFlame-Framework/blob/64f0e75c8ea28f12d8de66e7d4b6b96747cb4589/src/OfJSON.php

I changed it recently so it detects if json_last_error() is present, and if not it'll just throw an exception of code:
OfJSONException::ERR_JSON_UNKNOWN

The exception classes themselves are in src/OfException.php if you want to use that as well. Feel free to reuse the code with proper author/license notation, if you want.

@abraham abraham closed this as completed Aug 11, 2014
Repository owner locked and limited conversation to collaborators Dec 30, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants