【问题标题】:Fetch and parse the JSON in iOS在 iOS 中获取并解析 JSON
【发布时间】:2015-03-08 08:42:57
【问题描述】:

我正在按照http://www.appcoda.com/fetch-parse-json-ios-programming-tutorial/ 中提供的教程进行操作,我下载了代码并尝试运行它。当应用程序启动时,我得到了空白表格视图。我应该从网站上获取 JSON 数据并将其显示在表格视图中。

不知何故,在我看来,获取组方法没有被调用确实加载方法

@interface MasterViewController () <MeetupManagerDelegate> {
NSArray *_groups;
MeetupManager *_manager;
}

- (void)viewDidLoad
 {

[super viewDidLoad];

_manager = [[MeetupManager alloc] init];
_manager.communicator = [[MeetupCommunicator alloc] init];
_manager.communicator.delegate = _manager;
_manager.delegate = self;

[[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(startFetchingGroups:)
                                             name:@"kCLAuthorizationStatusAuthorized"
                                           object:nil];   // this should fetch the groups from the website but it isnt doing anything

}

#pragma mark - Notification Observer
- (void)startFetchingGroups:(NSNotification *)notification
{
[_manager fetchGroupsAtCoordinate:self.locationManager.location.coordinate];
}

谁能告诉我我错过了什么?

【问题讨论】:

    标签: ios json


    【解决方案1】:

    从未从 AppDelegate.m 发布 NSNotificationCenter“kCLAuthorizationStatusAuthorized”。

    当应用程序运行时,它应该询问您是否授权,然后才能使用位置浏览 Meetup。出于某种原因,它不要求授权。这可能与代码已经使用了几年,现在与 iOS8 相比已经过时了。

    试试这个更新的教程:http://www.appcoda.com/parse-xml-and-json-web-service/

    另外,看看如何仅从文本文件中解析 JSON(最佳答案):How do I parse JSON from a file in iOS?

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-08
      • 2012-05-01
      • 2017-02-11
      • 1970-01-01
      • 2014-02-07
      相关资源
      最近更新 更多