iOS JSON字符串转化为字典

释放双眼,带上耳机,听听看~!
#pragma mark -
- (void)getRongCloudTokenWith5151StudyID:(NSString *)studyID completed:(void(^)(NSString *IMToken))completed{
    NSString *url = [NSString stringWithFormat:@"users/%@/IMToken",studyID];
    [LFNetWorkManager requestDataBaseWithURLByGET:url parameters:nil isWithToken:NO completed:^(id responseObject) {
        NSString *dataStr = responseObject[@"data"];//JSON字符串
        NSData *jsonData = [dataStr dataUsingEncoding:NSUTF8StringEncoding];//转化为data
        NSDictionary *data = [NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingMutableContainers error:nil];//转化为字典
        NSInteger code = [responseObject[@"code"] integerValue];
        if (responseObject != nil && code==200) {
            if (completed){
                completed(data[@"token"]);
            }
        }else{
            if (completed){
                completed(nil);
            }
        }
    }];
}

 

人已赞赏
iOS文章

Xcode添加pch预编译文件

2019-10-29 1:35:25

iOS文章

iOS本地推送和取消本地推送服务

2019-10-29 4:26:21

个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
有新消息 消息中心
搜索