草庐IT

ios - 在 ios uitableview 中间歇性地获取 json 提要失败

coder 2024-01-26 原文

我正在构建一个简单的 ios 应用程序,它试图显示来自 flickr 的图像序列。问题是它有时有效,有时失败,我不确定哪里出了问题。 应用程序有一个主细节 View 。当前未使用 Detailview,问题发生在 master view 本身。我正在 masterview 上设置一个刷新按钮,并在用户尝试刷新时尝试重新获取数据。

github: https://github.com/kiranjulapalli/flickrexcercise

感谢任何见解。

这里是错误:

[MasterViewController connectionDidFinishLoading:] JSON error: The operation couldn’t be completed. (Cocoa error 3840.)

代码如下:

Header MasterViewController.h:
#import <UIKit/UIKit.h>
@interface MasterViewController : UITableViewController

@property (strong, nonatomic) NSMutableData* receivedData;
@property (strong, nonatomic) NSURLConnection *connection;
@property (strong, nonatomic) NSMutableArray* items;

@end

实现:

- (void)viewDidLoad
{
    [super viewDidLoad];

    UIBarButtonItem *addButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemRefresh target:self action:@selector(fetchFlickrData)];
    self.navigationItem.rightBarButtonItem = addButton;
    [self fetchFlickrData];
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView
 numberOfRowsInSection:(NSInteger)section
{
    if ( items != nil )
    {
        return items.count;
    }
    else
    {
        return 0;
    }
}

- (UITableViewCell *)tableView:(UITableView *)tableView
         cellForRowAtIndexPath:(NSIndexPath *)indexPath
{    
    static NSString *CellIdentifier = @"previewCell";

    previewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    if (cell == nil)
    {
        NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"previewCell" owner:self options:nil];
        cell = [nib objectAtIndex:0];
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    }
    NSDictionary* item = [items objectAtIndex:[indexPath row]];

    NSString* url = [[item objectForKey:@"media"] objectForKey:@"m"];

    [cell.photo setImageWithURL:[NSURL URLWithString:url]
                   placeholderImage:[UIImage imageNamed:@"thumbnail.jpg"]];
    return cell;
}

//获取数据

-(bool)fetchFlickrData {
    // build the url for fetching json data
    NSString* url = [NSString stringWithFormat:@"%@", FLICKR_PUBLIC_API_URI];

    // Escape the characters in the URL
    url = [url stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

    // Create the request.
    NSURLRequest *theRequest=[NSURLRequest requestWithURL:[NSURL URLWithString:url]
                                              cachePolicy:NSURLRequestUseProtocolCachePolicy
                                          timeoutInterval:20.0];

    connection=[[NSURLConnection alloc] initWithRequest:theRequest delegate:self];

    if (connection)
    {
        self.receivedData = [[NSMutableData alloc]init];
    }
    else
    { // Failed connection
        return false;
    }

    return true;
}

- (void)connection:(NSURLConnection *)connection
didReceiveResponse:(NSURLResponse *)response
{
    [self.receivedData setLength:0];
}

- (void)connection:(NSURLConnection *)connection
    didReceiveData:(NSData *)data
{
    [self.receivedData appendData:data];
}

- (void)connection:(NSURLConnection *)connection
  didFailWithError:(NSError *)error
{
    receivedData = nil;
    NSLog(@"Connection failed! Error - %@ %@",
          [error localizedDescription],
          [[error userInfo] objectForKey:NSURLErrorFailingURLStringErrorKey]);
}

--

- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{
    // do something with the data
    // receivedData is declared as a method instance elsewhere
    NSLog(@"Succeeded! Received %d bytes of data",[self.receivedData length]);

    NSString* stringcontents = [[NSString alloc] initWithData:self.receivedData encoding:NSUTF8StringEncoding];

    NSData *jsonData = [stringcontents dataUsingEncoding:NSUTF8StringEncoding];

    NSError *error = nil;

    NSDictionary *tempresults = jsonData ? [NSJSONSerialization JSONObjectWithData:jsonData options:0 error:&error] : nil;

    if (error) {

//*代码从上面继续: //这是我看到错误的地方,它大部分时间都在发生 //日志表明数据正常

        NSLog(@"[%@ %@] JSON error: %@", NSStringFromClass([self class]), NSStringFromSelector(_cmd), error.localizedDescription);
        NSLog(@"%@", stringcontents);
    }

    if ( !error )
    {

        NSDictionary* tempitems = [tempresults objectForKey:@"items" ];

        if ( !items )
        { // Allocate the mutable array if not already allocated
            items = [[NSMutableArray alloc]init];
        }
        else
        {
            [items removeAllObjects];
        }

        for (NSDictionary* item in tempitems)
        {
            [items addObject:item];
        }
        [self.tableView reloadData];
    }
    else
    {
        //Alert error
    }

    self.connection =nil;
}

报错时的内容:

{
        "title": "Uploads from everyone",
        "link": "http://www.flickr.com/photos/",
        "description": "",
        "modified": "2013-02-24T05:49:14Z",
        "generator": "http://www.flickr.com/",
        "items": [
       {
            "title": "P1610143",
            "link": "http://www.flickr.com/photos/jungandyu/8501768895/",
            "media": {"m":"http://farm9.staticflickr.com/8094/8501768895_2e05d3d266_m.jpg"},
            "date_taken": "2013-02-16T12:20:10-08:00",
            "description": " <p><a href=\"http://www.flickr.com/people/jungandyu/\">Bighead City<\/a> posted a photo:<\/p> <p><a href=\"http://www.flickr.com/photos/jungandyu/8501768895/\" title=\"P1610143\"><img src=\"http://farm9.staticflickr.com/8094/8501768895_2e05d3d266_m.jpg\" width=\"240\" height=\"180\" alt=\"P1610143\" /><\/a><\/p> ",
            "published": "2013-02-24T05:49:14Z",
            "author": "nobody@flickr.com (Bighead City)",
            "author_id": "19809616@N08",
            "tags": ""
       },
       {
            "title": "20121231-DSC08686.jpg",
            "link": "http://www.flickr.com/photos/wasicat/8501768957/",
            "media": {"m":"http://farm9.staticflickr.com/8385/8501768957_23f8a2fdcc_m.jpg"},
            "date_taken": "2012-12-31T12:52:35-08:00",
            "description": " <p><a href=\"http://www.flickr.com/people/wasicat/\">William0912<\/a> posted a photo:<\/p> <p><a href=\"http://www.flickr.com/photos/wasicat/8501768957/\" title=\"20121231-DSC08686.jpg\"><img src=\"http://farm9.staticflickr.com/8385/8501768957_23f8a2fdcc_m.jpg\" width=\"240\" height=\"180\" alt=\"20121231-DSC08686.jpg\" /><\/a><\/p> <p>201301015鎮西堡跨年<br /> 明新登山社<\/p>",
            "published": "2013-02-24T05:49:16Z",
            "author": "nobody@flickr.com (William0912)",
            "author_id": "81613772@N00",
            "tags": "鎮西堡 friendlyflickr 201301015鎮西堡跨年 明新登山社"
       },
       {
            "title": "IMAG0710",
            "link": "http://www.flickr.com/photos/84380329@N08/8501769085/",
            "media": {"m":"http://farm9.staticflickr.com/8231/8501769085_1433e589fe_m.jpg"},
            "date_taken": "2012-10-27T22:30:28-08:00",
            "description": " <p><a href=\"http://www.flickr.com/people/84380329@N08/\">bmota2007<\/a> posted a photo:<\/p> <p><a href=\"http://www.flickr.com/photos/84380329@N08/8501769085/\" title=\"IMAG0710\"><img src=\"http://farm9.staticflickr.com/8231/8501769085_1433e589fe_m.jpg\" width=\"135\" height=\"240\" alt=\"IMAG0710\" /><\/a><\/p> ",
            "published": "2013-02-24T05:49:20Z",
            "author": "nobody@flickr.com (bmota2007)",
            "author_id": "84380329@N08",
            "tags": ""
       },
       {
            "title": "IMAG0157.jpg",
            "link": "http://www.flickr.com/photos/58459890@N08/8501769129/",
            "media": {"m":"http://farm9.staticflickr.com/8532/8501769129_8becb3ccae_m.jpg"},
            "date_taken": "2012-09-08T23:55:12-08:00",
            "description": " <p><a href=\"http://www.flickr.com/people/58459890@N08/\">k7801101<\/a> posted a photo:<\/p> <p><a href=\"http://www.flickr.com/photos/58459890@N08/8501769129/\" title=\"IMAG0157.jpg\"><img src=\"http://farm9.staticflickr.com/8532/8501769129_8becb3ccae_m.jpg\" width=\"160\" height=\"240\" alt=\"IMAG0157.jpg\" /><\/a><\/p> ",
            "published": "2013-02-24T05:49:22Z",
            "author": "nobody@flickr.com (k7801101)",
            "author_id": "58459890@N08",
            "tags": ""
       },
       {
            "title": "The Press - Work at Rockville Metro Plaza I",
            "link": "http://www.flickr.com/photos/nakevanc/8501769159/",
            "media": {"m":"http://farm9.staticflickr.com/8234/8501769159_c68af16b82_m.jpg"},
            "date_taken": "2013-02-24T00:45:53-08:00",
            "description": " <p><a href=\"http://www.flickr.com/people/nakevanc/\">Nakeva<\/a> posted a photo:<\/p> <p><a href=\"http://www.flickr.com/photos/nakevanc/8501769159/\" title=\"The Press - Work at Rockville Metro Plaza I\"><img src=\"http://farm9.staticflickr.com/8234/8501769159_c68af16b82_m.jpg\" width=\"240\" height=\"180\" alt=\"The Press - Work at Rockville Metro Plaza I\" /><\/a><\/p> ",
            "published": "2013-02-24T05:49:22Z",
            "author": "nobody@flickr.com (Nakeva)",
            "author_id": "28116601@N02",
            "tags": ""
       },
       {
            "title": "BHS BBall Region Quarterfinals_1077.JPG",
            "link": "http://www.flickr.com/photos/kbaumann/8501769163/",
            "media": {"m":"http://farm9.staticflickr.com/8231/8501769163_3e54304c40_m.jpg"},
            "date_taken": "2013-02-23T18:32:15-08:00",
            "description": " <p><a href=\"http://www.flickr.com/people/kbaumann/\">kjbaumann<\/a> posted a photo:<\/p> <p><a href=\"http://www.flickr.com/photos/kbaumann/8501769163/\" title=\"BHS BBall Region Quarterfinals_1077.JPG\"><img src=\"http://farm9.staticflickr.com/8231/8501769163_3e54304c40_m.jpg\" width=\"159\" height=\"240\" alt=\"BHS BBall Region Quarterfinals_1077.JPG\" /><\/a><\/p> ",
            "published": "2013-02-24T05:49:22Z",
            "author": "nobody@flickr.com (kjbaumann)",
            "author_id": "33453969@N04",
            "tags": ""
       },
       {
            "title": "DSC_1458",
            "link": "http://www.flickr.com/photos/eddilui/8501769217/",
            "media": {"m":"http://farm9.staticflickr.com/8099/8501769217_43f83ea28b_m.jpg"},
            "date_taken": "2013-01-09T23:43:06-08:00",
            "description": " <p><a href=\"http://www.flickr.com/people/eddilui/\">Eddi Lui<\/a> posted a photo:<\/p> <p><a href=\"http://www.flickr.com/photos/eddilui/8501769217/\" title=\"DSC_1458\"><img src=\"http://farm9.staticflickr.com/8099/8501769217_43f83ea28b_m.jpg\" width=\"240\" height=\"160\" alt=\"DSC_1458\" /><\/a><\/p> ",
            "published": "2013-02-24T05:49:24Z",
            "author": "nobody@flickr.com (Eddi Lui)",
            "author_id": "68014013@N08",
            "tags": ""
       },
       {
            "title": "DSC_0112",
            "link": "http://www.flickr.com/photos/pjkdmd/8501769273/",
            "media": {"m":"http://farm9.staticflickr.com/8233/8501769273_63a9bb7206_m.jpg"},
            "date_taken": "2013-02-23T22:00:09-08:00",
            "description": " <p><a href=\"http://www.flickr.com/people/pjkdmd/\">pjkdmd<\/a> posted a photo:<\/p> <p><a href=\"http://www.flickr.com/photos/pjkdmd/8501769273/\" title=\"DSC_0112\"><img src=\"http://farm9.staticflickr.com/8233/8501769273_63a9bb7206_m.jpg\" width=\"240\" height=\"159\" alt=\"DSC_0112\" /><\/a><\/p> ",
            "published": "2013-02-24T05:49:25Z",
            "author": "nobody@flickr.com (pjkdmd)",
            "author_id": "81759199@N08",
            "tags": ""
       },
       {
            "title": "8499469359_a854f58ba3_z",
            "link": "http://www.flickr.com/photos/ury94/8501769293/",
            "media": {"m":"http://farm9.staticflickr.com/8093/8501769293_f19a12de4f_m.jpg"},
            "date_taken": "2013-02-24T06:49:26-08:00",
            "description": " <p><a href=\"http://www.flickr.com/people/ury94/\">Hồng Anh ®<\/a> posted a photo:<\/p> <p><a href=\"http://www.flickr.com/photos/ury94/8501769293/\" title=\"8499469359_a854f58ba3_z\"><img src=\"http://farm9.staticflickr.com/8093/8501769293_f19a12de4f_m.jpg\" width=\"160\" height=\"240\" alt=\"8499469359_a854f58ba3_z\" /><\/a><\/p> ",
            "published": "2013-02-24T05:49:26Z",
            "author": "nobody@flickr.com (Hồng Anh ®)",
            "author_id": "39951352@N03",
            "tags": ""
       },
       {
            "title": "Punggol End",
            "link": "http://www.flickr.com/photos/eideticme/8502873874/",
            "media": {"m":"http://farm9.staticflickr.com/8242/8502873874_790c93ed5b_m.jpg"},
            "date_taken": "2012-05-26T23:29:17-08:00",
            "description": " <p><a href=\"http://www.flickr.com/people/eideticme/\">eidetic.me<\/a> posted a photo:<\/p> <p><a href=\"http://www.flickr.com/photos/eideticme/8502873874/\" title=\"Punggol End\"><img src=\"http://farm9.staticflickr.com/8242/8502873874_790c93ed5b_m.jpg\" width=\"240\" height=\"160\" alt=\"Punggol End\" /><\/a><\/p> ",
            "published": "2013-02-24T05:49:14Z",
            "author": "nobody@flickr.com (eidetic.me)",
            "author_id": "76188829@N02",
            "tags": ""
       },
       {
            "title": "IMG_0597",
            "link": "http://www.flickr.com/photos/mediaocu/8502873916/",
            "media": {"m":"http://farm9.staticflickr.com/8381/8502873916_a9cb6e726a_m.jpg"},
            "date_taken": "2013-02-23T04:39:39-08:00",
            "description": " <p><a href=\"http://www.flickr.com/people/mediaocu/\">MediaOCU<\/a> posted a photo:<\/p> <p><a href=\"http://www.flickr.com/photos/mediaocu/8502873916/\" title=\"IMG_0597\"><img src=\"http://farm9.staticflickr.com/8381/8502873916_a9cb6e726a_m.jpg\" width=\"240\" height=\"160\" alt=\"IMG_0597\" /><\/a><\/p> <p>The OCU spirit squad performed at a spirit competition in the Henry J Freede activity and wellness center on Saturday afternoon.<br /> <br /> The Campus/Michael Horn<\/p>",
            "published": "2013-02-24T05:49:16Z",
            "author": "nobody@flickr.com (MediaOCU)",
            "author_id": "86702597@N04",
            "tags": ""
       },
       {
            "title": "Squaw Valley ski trip",
            "link": "http://www.flickr.com/photos/hallucinant/8502873920/",
            "media": {"m":"http://farm9.staticflickr.com/8391/8502873920_e207276293_m.jpg"},
            "date_taken": "2013-02-22T10:30:59-08:00",
            "description": " <p><a href=\"http://www.flickr.com/people/hallucinant/\">hallucinant<\/a> posted a photo:<\/p> <p><a href=\"http://www.flickr.com/photos/hallucinant/8502873920/\" title=\"Squaw Valley ski trip\"><img src=\"http://farm9.staticflickr.com/8391/8502873920_e207276293_m.jpg\" width=\"240\" height=\"160\" alt=\"Squaw Valley ski trip\" /><\/a><\/p> ",
            "published": "2013-02-24T05:49:16Z",
            "author": "nobody@flickr.com (hallucinant)",
            "author_id": "62641951@N00",
            "tags": ""
       },
       {
            "title": "053/365",
            "link": "http://www.flickr.com/photos/originalrocker/8502873948/",
            "media": {"m":"http://farm9.staticflickr.com/8385/8502873948_06c8800be5_m.jpg"},
            "date_taken": "2013-02-22T19:37:35-08:00",
            "description": " <p><a href=\"http://www.flickr.com/people/originalrocker/\">originalrocker<\/a> posted a photo:<\/p> <p><a href=\"http://www.flickr.com/photos/originalrocker/8502873948/\" title=\"053/365\"><img src=\"http://farm9.staticflickr.com/8385/8502873948_06c8800be5_m.jpg\" width=\"240\" height=\"180\" alt=\"053/365\" /><\/a><\/p> <p>worst feeling ever: when your little one is feeling bad with a high fever, and you can only do so much. :(<\/p>",
            "published": "2013-02-24T05:49:17Z",
            "author": "nobody@flickr.com (originalrocker)",
            "author_id": "49882128@N00",
            "tags": "max project day ruben tracy 365 homies guzman maximiliano 2013 365dayproject uploaded:by=flickrmobile flickriosapp:filter=nofilter"
       },
       {
            "title": "Oh qu\'il est haut, le pont du Bono...",
            "link": "http://www.flickr.com/photos/dyc56/8502873962/",
            "media": {"m":"http://farm9.staticflickr.com/8239/8502873962_a1851d4140_m.jpg"},
            "date_taken": "2013-01-13T16:24:20-08:00",
            "description": " <p><a href=\"http://www.flickr.com/people/dyc56/\">DYC56<\/a> posted a photo:<\/p> <p><a href=\"http://www.flickr.com/photos/dyc56/8502873962/\" title=\"Oh qu\'il est haut, le pont du Bono...\"><img src=\"http://farm9.staticflickr.com/8239/8502873962_a1851d4140_m.jpg\" width=\"240\" height=\"204\" alt=\"Oh qu\'il est haut, le pont du Bono...\" /><\/a><\/p> ",
            "published": "2013-02-24T05:49:17Z",
            "author": "nobody@flickr.com (DYC56)",
            "author_id": "76919092@N08",
            "tags": "bridge france art soleil eau lumière pierre bretagne breizh pont bateau morbihan soe hdr bois nikond700 ahhhlafrance nikonpassion pixeliste nikkor1424mmf28g bretagnesanspareil mordusdephotos bouboun56"
       },
       {
            "title": "Playing a rehearsal tomorrow and the lead sheets will be only on my iPad. Lets see how this goes!",
            "link": "http://www.flickr.com/photos/jasondegenhardt/8502874026/",
            "media": {"m":"http://farm9.staticflickr.com/8245/8502874026_c39b545160_m.jpg"},
            "date_taken": "2013-02-23T23:49:19-08:00",
            "description": " <p><a href=\"http://www.flickr.com/people/jasondegenhardt/\">jasondeg<\/a> posted a photo:<\/p> <p><a href=\"http://www.flickr.com/photos/jasondegenhardt/8502874026/\" title=\"Playing a rehearsal tomorrow and the lead sheets will be only on my iPad. Lets see how this goes!\"><img src=\"http://farm9.staticflickr.com/8245/8502874026_c39b545160_m.jpg\" width=\"240\" height=\"240\" alt=\"Playing a rehearsal tomorrow and the lead sheets will be only on my iPad. Lets see how this goes!\" /><\/a><\/p> ",
            "published": "2013-02-24T05:49:19Z",
            "author": "nobody@flickr.com (jasondeg)",
            "author_id": "40834611@N06",
            "tags": "square squareformat iphoneography instagramapp uploaded:by=instagram foursquare:venue=50daa303e4b019a9f2725785"
       },
       {
            "title": "IMG_0588",
            "link": "http://www.flickr.com/photos/hmclin/8502874044/",
            "media": {"m":"http://farm9.staticflickr.com/8383/8502874044_7caebe46c5_m.jpg"},
            "date_taken": "2013-02-23T18:01:42-08:00",
            "description": " <p><a href=\"http://www.flickr.com/people/hmclin/\">Henry McLin<\/a> posted a photo:<\/p> <p><a href=\"http://www.flickr.com/photos/hmclin/8502874044/\" title=\"IMG_0588\"><img src=\"http://farm9.staticflickr.com/8383/8502874044_7caebe46c5_m.jpg\" width=\"240\" height=\"160\" alt=\"IMG_0588\" /><\/a><\/p> ",
            "published": "2013-02-24T05:49:20Z",
            "author": "nobody@flickr.com (Henry McLin)",
            "author_id": "95014738@N00",
            "tags": ""
       },
       {
            "title": "",
            "link": "http://www.flickr.com/photos/n28307/8502874096/",
            "media": {"m":"http://farm9.staticflickr.com/8228/8502874096_2494bd2d14_m.jpg"},
            "date_taken": "2013-02-23T09:29:12-08:00",
            "description": " <p><a href=\"http://www.flickr.com/people/n28307/\">beltz6<\/a> posted a photo:<\/p> <p><a href=\"http://www.flickr.com/photos/n28307/8502874096/\" title=\"\"><img src=\"http://farm9.staticflickr.com/8228/8502874096_2494bd2d14_m.jpg\" width=\"240\" height=\"160\" alt=\"\" /><\/a><\/p> ",
            "published": "2013-02-24T05:49:21Z",
            "author": "nobody@flickr.com (beltz6)",
            "author_id": "23089307@N02",
            "tags": "mesa ucsb universityofcalifornia afsdxvrzoomnikkor18200mmf3556gifedii"
       },
       {
            "title": "bristow_party_124",
            "link": "http://www.flickr.com/photos/amyherndonphotography/8502874102/",
            "media": {"m":"http://farm9.staticflickr.com/8236/8502874102_7192f5c6f0_m.jpg"},
            "date_taken": "2013-02-17T00:16:46-08:00",
            "description": " <p><a href=\"http://www.flickr.com/people/amyherndonphotography/\">amy herndon<\/a> posted a photo:<\/p> <p><a href=\"http://www.flickr.com/photos/amyherndonphotography/8502874102/\" title=\"bristow_party_124\"><img src=\"http://farm9.staticflickr.com/8236/8502874102_7192f5c6f0_m.jpg\" width=\"180\" height=\"240\" alt=\"bristow_party_124\" /><\/a><\/p> ",
            "published": "2013-02-24T05:49:22Z",
            "author": "nobody@flickr.com (amy herndon)",
            "author_id": "62464749@N08",
            "tags": ""
       },
       {
            "title": "100_1764",
            "link": "http://www.flickr.com/photos/lelikadgi/8502874124/",
            "media": {"m":"http://farm9.staticflickr.com/8237/8502874124_9a7a7f356e_m.jpg"},
            "date_taken": "2005-08-17T12:46:26-08:00",
            "description": " <p><a href=\"http://www.flickr.com/people/lelikadgi/\">lelikadgi<\/a> posted a photo:<\/p> <p><a href=\"http://www.flickr.com/photos/lelikadgi/8502874124/\" title=\"100_1764\"><img src=\"http://farm9.staticflickr.com/8237/8502874124_9a7a7f356e_m.jpg\" width=\"180\" height=\"240\" alt=\"100_1764\" /><\/a><\/p> ",
            "published": "2013-02-24T05:49:22Z",
            "author": "nobody@flickr.com (lelikadgi)",
            "author_id": "77157992@N04",
            "tags": ""
       },
       {
            "title": "@eliseebrown",
            "link": "http://www.flickr.com/photos/jj_delrosario/8502874178/",
            "media": {"m":"http://farm9.staticflickr.com/8376/8502874178_5c32893a8e_m.jpg"},
            "date_taken": "2013-02-24T00:49:24-08:00",
            "description": " <p><a href=\"http://www.flickr.com/people/jj_delrosario/\">jj_delrosario<\/a> posted a photo:<\/p> <p><a href=\"http://www.flickr.com/photos/jj_delrosario/8502874178/\" title=\"@eliseebrown\"><img src=\"http://farm9.staticflickr.com/8376/8502874178_5c32893a8e_m.jpg\" width=\"240\" height=\"240\" alt=\"@eliseebrown\" /><\/a><\/p> ",
            "published": "2013-02-24T05:49:24Z",
            "author": "nobody@flickr.com (jj_delrosario)",
            "author_id": "57743051@N03",
            "tags": "square squareformat iphoneography instagramapp uploaded:by=instagram foursquare:venue=4b7e974ef964a5203df42fe3"
       }
        ]
}

最佳答案

使用 NSLog(@"%@", [error debugDescription]); 进一步调试问题。

关于ios - 在 ios uitableview 中间歇性地获取 json 提要失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15048955/

有关ios - 在 ios uitableview 中间歇性地获取 json 提要失败的更多相关文章

  1. ruby-on-rails - Rails HTML 请求渲染 JSON - 2

    在我的Controller中,我通过以下方式在我的index方法中支持HTML和JSON:respond_todo|format|format.htmlformat.json{renderjson:@user}end在浏览器中拉起它时,它会自然地以HTML呈现。但是,当我对/user资源进行内容类型为application/json的curl调用时(因为它是索引方法),我仍然将HTML作为响应。如何获取JSON作为响应?我还需要说明什么? 最佳答案 您应该将.json附加到请求的url,提供的格式在routes.rb的路径中定义。这

  2. ruby - 即使失败也继续进行多主机测试 - 2

    我已经构建了一些serverspec代码来在多个主机上运行一组测试。问题是当任何测试失败时,测试会在当前主机停止。即使测试失败,我也希望它继续在所有主机上运行。Rakefile:namespace:specdotask:all=>hosts.map{|h|'spec:'+h.split('.')[0]}hosts.eachdo|host|begindesc"Runserverspecto#{host}"RSpec::Core::RakeTask.new(host)do|t|ENV['TARGET_HOST']=hostt.pattern="spec/cfengine3/*_spec.r

  3. ruby - 简单获取法拉第超时 - 2

    有没有办法在这个简单的get方法中添加超时选项?我正在使用法拉第3.3。Faraday.get(url)四处寻找,我只能先发起连接后应用超时选项,然后应用超时选项。或者有什么简单的方法?这就是我现在正在做的:conn=Faraday.newresponse=conn.getdo|req|req.urlurlreq.options.timeout=2#2secondsend 最佳答案 试试这个:conn=Faraday.newdo|conn|conn.options.timeout=20endresponse=conn.get(url

  4. ruby - 如何验证 IO.copy_stream 是否成功 - 2

    这里有一个很好的答案解释了如何在Ruby中下载文件而不将其加载到内存中:https://stackoverflow.com/a/29743394/4852737require'open-uri'download=open('http://example.com/image.png')IO.copy_stream(download,'~/image.png')我如何验证下载文件的IO.copy_stream调用是否真的成功——这意味着下载的文件与我打算下载的文件完全相同,而不是下载一半的损坏文件?documentation说IO.copy_stream返回它复制的字节数,但是当我还没有下

  5. ruby - 从 Ruby 中的主机名获取 IP 地址 - 2

    我有一个存储主机名的Ruby数组server_names。如果我打印出来,它看起来像这样:["hostname.abc.com","hostname2.abc.com","hostname3.abc.com"]相当标准。我想要做的是获取这些服务器的IP(可能将它们存储在另一个变量中)。看起来IPSocket类可以做到这一点,但我不确定如何使用IPSocket类遍历它。如果它只是尝试像这样打印出IP:server_names.eachdo|name|IPSocket::getaddress(name)pnameend它提示我没有提供服务器名称。这是语法问题还是我没有正确使用类?输出:ge

  6. ruby - 获取模块中定义的所有常量的值 - 2

    我想获取模块中定义的所有常量的值:moduleLettersA='apple'.freezeB='boy'.freezeendconstants给了我常量的名字:Letters.constants(false)#=>[:A,:B]如何获取它们的值的数组,即["apple","boy"]? 最佳答案 为了做到这一点,请使用mapLetters.constants(false).map&Letters.method(:const_get)这将返回["a","b"]第二种方式:Letters.constants(false).map{|c

  7. ruby-on-rails - 获取 inf-ruby 以使用 ruby​​ 版本管理器 (rvm) - 2

    我安装了ruby​​版本管理器,并将RVM安装的ruby​​实现设置为默认值,这样'哪个ruby'显示'~/.rvm/ruby-1.8.6-p383/bin/ruby'但是当我在emacs中打开inf-ruby缓冲区时,它使用安装在/usr/bin中的ruby​​。有没有办法让emacs像shell一样尊重ruby​​的路径?谢谢! 最佳答案 我创建了一个emacs扩展来将rvm集成到emacs中。如果您有兴趣,可以在这里获取:http://github.com/senny/rvm.el

  8. Ruby 文件 IO 定界符? - 2

    我正在尝试解析一个文本文件,该文件每行包含可变数量的单词和数字,如下所示:foo4.500bar3.001.33foobar如何读取由空格而不是换行符分隔的文件?有什么方法可以设置File("file.txt").foreach方法以使用空格而不是换行符作为分隔符? 最佳答案 接受的答案将slurp文件,这可能是大文本文件的问题。更好的解决方案是IO.foreach.它是惯用的,将按字符流式传输文件:File.foreach(filename,""){|string|putsstring}包含“thisisanexample”结果的

  9. Ruby 从大范围中获取第 n 个项目 - 2

    假设我有这个范围:("aaaaa".."zzzzz")如何在不事先/每次生成整个项目的情况下从范围中获取第N个项目? 最佳答案 一种快速简便的方法:("aaaaa".."zzzzz").first(42).last#==>"aaabp"如果出于某种原因你不得不一遍又一遍地这样做,或者如果你需要避免为前N个元素构建中间数组,你可以这样写:moduleEnumerabledefskip(n)returnto_enum:skip,nunlessblock_given?each_with_indexdo|item,index|yieldit

  10. ruby - Net::HTTP 获取源代码和状态 - 2

    我目前正在使用以下方法获取页面的源代码:Net::HTTP.get(URI.parse(page.url))我还想获取HTTP状态,而无需发出第二个请求。有没有办法用另一种方法做到这一点?我一直在查看文档,但似乎找不到我要找的东西。 最佳答案 在我看来,除非您需要一些真正的低级访问或控制,否则最好使用Ruby的内置Open::URI模块:require'open-uri'io=open('http://www.example.org/')#=>#body=io.read[0,50]#=>"["200","OK"]io.base_ur

随机推荐