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

bug fix: when input object is not a valid JSON object, in - (void)put… #35

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

Conversation

lanjing99
Copy link

…Object:(id)object withId:(NSString *)objectId intoTable:(NSString *)tableName, do NOT throw an exception

…Object:(id)object withId:(NSString *)objectId intoTable:(NSString *)tableName, do NOT throw an exception
NSError * error;
NSData * data = [NSJSONSerialization dataWithJSONObject:object options:0 error:&error];
if (error) {
if([NSJSONSerialization isValidJSONObject:object] == NO){
debugLog(@"ERROR, faild to get json data");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这样改有什么好处吗?我感觉性能会下降。

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

当传入参数不是合法 JSON 对象时,dataWithJSONObject 会 crash。 AFNetworking 前几天做了类似的改动 AFNetworking/AFNetworking@719a3bf

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

不过考虑到暴露出的 API 没有通过 error 或者返回值报告操作成功与否,只是打出了 log。相比之下,Crash 也不失为一种报错的方式。

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

谢谢,我拉同事过来一起讨论一下。

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.

3 participants