iOS最成熟的REST服务库

iOS最成熟的REST服务库

本文介绍了iOS最成熟的REST服务库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我想通过iOS应用访问REST服务,最成熟的库是什么?我最好的选择是什么?

If I want to hit REST services from an iOS app what is the most mature library for doing so?What are my best options?

推荐答案

您可以使用 RestKit

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

Or you can use NSJSONSerialization which is already in the foundation framework.

这是我所做的一个项目的例子.它从json网络服务中获取一系列饮料:

Here's an exemple from a project that i made. It fetch an array of drinks from a 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];
    }
}

这篇关于iOS最成熟的REST服务库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-03 03:23