【问题标题】:IOS6 JSON.H import in main viewcontroller (Xcode5)IOS6 JSON.H 导入主视图控制器(Xcode5)
【发布时间】:2013-11-21 06:12:51
【问题描述】:

我是 ios 新手,所以为了获得 accesstoken,我点击了链接 http://technogerms.com/login-with-google-using-oauth-2-0-for-ios-xcode-objective-c/ .so 在这些链接中他们使用 json.h 文件是强制性的。如果是,请在这些链接中向我解释有关 json github 的信息。

【问题讨论】:

    标签: objective-c json xcode ios6


    【解决方案1】:

    这是你想要的链接。

    https://github.com/johnezang/JSONKit

    【讨论】:

      【解决方案2】:

      使用原生 NSJSONSerialization 类,您可以在下面的链接中找到更多信息,

      iOS NSJSONSerialization

      How to use NSJSONSerialization

      【讨论】:

        【解决方案3】:

        在您的项目中没有强制使用 JSON.h。现在您可以使用内置的苹果 JSON 解析器。如果你想下载 JSon 库,那么链接是

        Download JSon file from here

        否则你可以通过以下方法使用这个内置的苹果 JSON 解析器。

         NSDictionary *res = [NSJSONSerialization JSONObjectWithData:responseData options:NSJSONReadingMutableLeaves || NSJSONReadingMutableContainers error:&myError];
        

        完整代码如下:

         NSString *urlString=[NSString stringWithFormat:@"%@listcontact.php?uid=%@&page=0",LocalPath,appdel.strid]; //---- Add your URL for webservice-----
        
         NSURL *url = [NSURL URLWithString:urlString];
        
         NSURLRequest *urlRequest = [NSURLRequest requestWithURL:url];
        
         There are two NSURLConnection request methods AsynchronousRequest and SynchronousRequest.
        
         (1) For AsynchronousRequest
        
         [NSURLConnection sendAsynchronousRequest:urlRequest queue:[NSOperationQueue currentQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *error)
         {
             NSError *error1;
             NSDictionary *res=[NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableLeaves error:&error1];
         }];
        
         (2) For SynchronousRequest
        
           NSData *GETReply = [NSURLConnection sendSynchronousRequest:urlRequest returningResponse:nil error:nil];
           NSError *myError = nil;
        
           NSDictionary *res = [NSJSONSerialization JSONObjectWithData:GETReply options:NSJSONReadingMutableLeaves error:&myError]; 
        

        【讨论】:

        • 我想使用苹果 JSON Parser 解释一下你提供的代码,在哪里以及如何放置?谢谢
        • @ChetanKumar 查看我更新的代码。如果您有任何疑问,可以联系我
        猜你喜欢
        • 1970-01-01
        • 2014-01-16
        • 1970-01-01
        • 2023-03-17
        • 1970-01-01
        • 1970-01-01
        • 2023-03-24
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多