1

我有一个早期运行 IOS 5 的项目。我必须让项目在 IOS 4.3 上运行。当我运行该项目时,我在以下书面方法中遇到了 2 个错误。
我得到的错误已被评论。任何可能的解决方案。我是 Iphone 新手。请帮助:)

此方法解析来自服务器的响应并转换为应用程序的模型表示。

+ (NSArray*) parseResponse:(NSData *) data {
  NSDictionary* json = nil;
Class jsonSerializationClass = NSClassFromString(@"NSJSONSerialization");
  if (data) {
  json = [NSJSONSerialization  // error: Use of undeclared identifier  
                              // 'NSJSONSerialization'
            JSONObjectWithData:data
            options:kNilOptions
            error:nil];
  }
   NSLog(@"Total contacts fetched: %u",[json[@"contacts"] count]);
   NSMutableArray *contacts =[[NSMutableArray alloc] init];
   for (NSInteger i=0;i<[json[@"contacts"] count];i++){ //error: Array subscript is not 
                                                     //interger
   NSLog(@"Name %@ ",json[@"contacts"][i][@"lastName"]);
    Contact *aContact=[[Contact alloc]initWithFirstName:json[@"contacts"][i] 
      [@"firstName"]
                                            andLastName:json[@"contacts"][i]
       [@"lastName"]
                                               andEmail:json[@"contacts"][i][@"email"] 
      andPhone:json[@"contacts"][i][@"phone"]];
    [contacts addObject:aContact];
   }
  return contacts;
  }
4

1 回答 1

1

NSJSONSerialization is available only in iOS 5.0 and above.

Here is the documentation NSJSONSerialization

For earlier iOS versions, you could use SBJsonParser or something else.

于 2012-12-24T16:03:05.250 回答