iOS NSString 转 字典NSDictionary

2018-12-24  本文已影响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;
}
上一篇下一篇

猜你喜欢

热点阅读