iOS最成熟的REST服务库

如果我想从iOS应用程序中获得REST服务,那么这样做的最成熟的库是什么? 我最好的select是什么?

你可以使用RestKit 。

或者你可以使用已经在基础框架中的NSJSONSerialization

这是我做的一个项目的例子。 它从json webservice获取一系列饮料:

  NSString *urlString= [NSString stringWithFormat:@"my json webservice URL"]; NSURL *url = [NSURL URLWithString:urlString]; NSData *data = [NSData dataWithContentsOfURL:url]; NSError *error; NSDictionary *jsonResultSet = (NSDictionary*)[NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:&error]; if ([jsonResultSet count] !=0){ NSArray* drinks = [jsonResultSet objectForKey:@"drinks"]; for (NSDictionary* drinkDictionary in drinks) { Drink* drink = [[Drink alloc] initWithDictionary:drinkDictionary]; [[DrinkList getInstance]addDrinksWithObject:drink]; } } 

我build议AFNetworking 。 以下是从其Github页面获取的示例代码(在那里有更多的示例):

 NSURL *url = [NSURL URLWithString:@"https://alpha-api.app.net/stream/0/posts/stream/global"]; NSURLRequest *request = [NSURLRequest requestWithURL:url]; AFJSONRequestOperation *operation = [AFJSONRequestOperation JSONRequestOperationWithRequest:request success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON) { NSLog(@"App.net Global Stream: %@", JSON); } failure:nil]; [operation start]; 

其他select是:

  • RestKit
  • LRResty
  • MKNetworkKit

其中,我认为AFNetworking和RestKit是最受欢迎的。 我个人曾经广泛使用AFNetworking,所以我推荐它。

不是那么成熟,但重量很轻: JNRestClient

还有一个叫做Alamofire( https://github.com/Alamofire/Alamofire )的新的快速rest库,它看起来非常好,它已经在github上有超过6000颗星星了,它是由Mattt Thompson创build的,这意味着你可以去无忧无虑。

JSONModel使用起来相当简单。

大衣 + 地幔看起来非常好。

RestKit有点冗长,恕我直言。