ios – 如何从NSURLSessionTask获取响应字符串

前端之家收集整理的这篇文章主要介绍了ios – 如何从NSURLSessionTask获取响应字符串前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在使用AFNetwork 3.0进行HTTP get请求.
我甚至得到了回应.但我想将响应数据作为NSString.
有人可以帮助我如何获取响应数据作为NSString

这是我的代码,

AFHTTPSessionManager *operation = [AFHTTPSessionManager alloc];

    [operation GET:controlURL.absoluteString parameters:nil progress:nil success:^(NSURLSessionTask *task,id responSEObject) {
        NSLog(@"JSON: %@",responSEObject);


        NSLog(@"success: %@",responSEObject);

        NSString *xmlString = [responSEObject ];// i am facing problem here

解决方法

如果您想在字符串中使用响应数据,请尝试以下操作:

NSString *str = [[NSString alloc] initWithData:responSEObject encoding:NSUTF8StringEncoding];
    NSLog(@"responseData: %@",str);

猜你在找的Xcode相关文章