0

The below is the code I used to get a data of URL from a facebook page. I need to display those datas in a view. How to do it?

NSURL *URL = [NSURL URLWithString:@"https://www.facebook.com/104958162837/posts/10151442797857838"];
NSURLRequest* request = [NSURLRequest requestWithURL:URL];

[NSURLConnection sendAsynchronousRequest:request
                                   queue:[NSOperationQueue mainQueue]
                       completionHandler:^(NSURLResponse * response,
                                           NSData * data,
                                           NSError * error) {
                           if (!error){

                               NSLog(@"%@",data);

                               // I want to render this data in a view.

                           }

                       }];

I can get the proper values in the in NSData. I want to display those datas in a webview or uilabel or something to display those datas.

4

2 回答 2

2

请参阅此代码。

id dataObject = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:nil];

您可以将 json 字符串获取到 NSObject(如 NSDictionary、NSArray)

于 2013-03-05T05:22:09.303 回答
1

您需要转换NSDataNSString然后将其NSString用于显示。

NSURL *URL = [NSURL URLWithString:@"https://www.facebook.com/xxxxxx/posts/xxxxxxxxxx"];
NSURLRequest* request = [NSURLRequest requestWithURL:URL];

[NSURLConnection sendAsynchronousRequest:request
                                   queue:[NSOperationQueue mainQueue]
                       completionHandler:^(NSURLResponse * response,
                                           NSData * data,
                                           NSError * error) {
                           if (!error){

                               NSLog(@"%@",data);

                               // I want to render this data in a view.
                               NSString *myString = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];

                               //[lbl setText:myString];

                                /** EDIT : As you are getting HTML Response, you can display that in WebView like this **/

                               [webview loadHTMLString:myString baseURL:nil];



                           }

                       }];
于 2013-03-05T05:12:11.057 回答