美文网首页
使用NSJSONSerialization序列化返回了NSNul

使用NSJSONSerialization序列化返回了NSNul

作者: 大成小栈 | 来源:发表于2022-03-08 14:54 被阅读0次

我们在使用NSJSONSerialization序列化字符串时,对于不同的输入字符串可能会有特殊处理。

1. 入参为@"null"时

NSString *resultStr = @"null";
    NSError *error = nil;
    NSDictionary *resultDic = [NSJSONSerialization JSONObjectWithData:[resultStr dataUsingEncoding:NSUTF8StringEncoding] options:NSJSONReadingFragmentsAllowed error:&error];
    
    NSLog(@"%@", resultDic);

2. 入参为@"nullTest"时

NSString *resultStr = @"nullTest";
    NSError *error = nil;
    NSDictionary *resultDic = [NSJSONSerialization JSONObjectWithData:[resultStr dataUsingEncoding:NSUTF8StringEncoding] options:NSJSONReadingFragmentsAllowed error:&error];
    
    NSLog(@"%@", resultDic);

有意思不🤣

相关文章

网友评论

      本文标题:使用NSJSONSerialization序列化返回了NSNul

      本文链接:https://www.haomeiwen.com/subject/yryarrtx.html