美文网首页
iOS NSString 转 字典NSDictionary

iOS NSString 转 字典NSDictionary

作者: 舒翱 | 来源:发表于2018-12-24 15:42 被阅读0次
    #pragma mark - NSString 转 字典NSDictionary
    - (NSDictionary *)dictionaryWithJsonString:(NSString *)jsonString {
        if (jsonString == nil) {
            return nil;
        }
        NSData *jsonData = [jsonString dataUsingEncoding:NSUTF8StringEncoding];
        NSError *err;
        NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:jsonData
                                                            options:NSJSONReadingMutableContainers
                                                              error:&err];
        if(err) {/*JSON解析失败*/
    
            return nil;
        }
        return dic;
    }
    

    相关文章

      网友评论

          本文标题:iOS NSString 转 字典NSDictionary

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