我正在从服务器获取数据,它作为响应提供了一个 NSString,其中包含 json 数据我希望将 json 数据存储在一个数组中如何做到这一点
NSData *urlData=[NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
NSString *data=[[NSString alloc]initWithData:urlData encoding:NSUTF8StringEncoding];
NSLog(data);
NSData* data=[dataString dataUsingEncoding:NSUTF8StringEncoding];
[self performSelectorOnMainThread:@selector(fetchedData:)
withObject:data waitUntilDone:YES];
- (void)fetchedData:(NSData *)responseData {
//parse out the json data
NSError* error;
NSDictionary* json = [NSJSONSerialization
JSONObjectWithData:responseData //1
options:kNilOptions
error:&error];
NSArray* latestLoans = [json objectForKey:@"loans"]; //2
NSLog(@"loans: %@", latestLoans); //3
}
这是从服务器返回的数据日志
[{"CodeValue":"90658","CodeDescription":"flu shot","IsActive":"1","CodeType":"CPT","CodeID":"6","UpdateDateTime":"2012-04-02 02:09:46"}]