1
我想用我的iOS應用程序獲取此JSON數據:https://sleepy-journey-2871.herokuapp.com/users.json .... RestKit嘗試從url中獲取這些用戶,但它返回0個對象並且顯示「無可映射在搜索到的關鍵路徑上找到表示,沒有響應描述符匹配加載的響應。「RestKit - 從Rails應用程序中獲取JSON數組
請幫我弄清楚我失蹤或做錯了什麼!我一直在爲此奮戰數星期。
我的Xcode 5.0.2,我成功安裝RestKit用的CocoaPods和Podfile,看起來像這樣:
platform :ios, '6.0'
pod 'RestKit', '~> 0.22.0'
pod 'RestKit/Testing'
pod 'RestKit/Search'
我AppDelegate.m文件如下(在didFinishLaunchingWithOptions方法):
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.
//Set base url
NSString *baseUrl = @"https://sleepy-journey-2871.herokuapp.com";
//initialize the the http client with baseUrl
AFHTTPClient *httpClient = [[AFHTTPClient alloc] initWithBaseURL:[NSURL URLWithString:baseUrl]];
//initialize the RKObjectManager with our http client
RKObjectManager *manager = [[RKObjectManager alloc] initWithHTTPClient:httpClient];
//add text/plain as a JSON content type to properly parse errors
[RKMIMETypeSerialization registerClass:[RKNSJSONSerialization class] forMIMEType:@"text/plain"];
//register JSONRequestOperation to parse JSON in requests
[manager.HTTPClient registerHTTPOperationClass:[AFJSONRequestOperation class]];
//state that we are accepting JSON content type
[manager setAcceptHeaderWithMIMEType:RKMIMETypeJSON];
//configure so that we want the outgoing objects to be serialized into JSON
manager.requestSerializationMIMEType = RKMIMETypeJSON;
//set the shared instance of the object manager, so that we can easily re-use it later
[RKObjectManager setSharedManager:manager];
return YES;
}
我在視圖控制器的viewDidLoad方法,首先負載時所述應用啓動此代碼:
- (void)viewDidLoad
{
[super viewDidLoad];
RKObjectManager *manager = [RKObjectManager sharedManager];
[manager getObjectsAtPath:@"/users"
parameters:nil
success:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult)
{
NSLog(@"Loaded databases: %@", [mappingResult array]);
}
failure:^(RKObjectRequestOperation *operation, NSError *error)
{
NSLog(@"Error: %@", [error localizedDescription]);
}];
// Do any additional setup after loading the view, typically from a nib.
}
那麼'RKObjectRequestOperation *操作...'部分及其下面的部分仍然在該用戶類中? 「運行開始」代碼何時運行? – EAB