我已经从 json 调用中下载了一些 json 数据,现在我正在尝试将以下 json 解析为一个数组,以便我可以在我的 NSlog 中看到问题列表?
例如
NSLog(@"Questions:Air cleaner (Primary), Air Cleaner (Secondary));
[
{"SurveyAnswerTypeID":4,"Question":"Air cleaner (Primary)"},
{"SurveyAnswerTypeID":4,"Question":"Air Cleaner (Secondary)"}
]
我试图将它放入一个数组中,它只会返回一个数组,例如空气净化器(初级)
NSString *searchQuery = [NSString stringWithFormat:@"http://www.ddproam.co.za/Central/Survey/GetSurveyQuestions?surveyId=%@",self.surveyQuestionIDParsed];
searchQuery = [searchQuery stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSData *dataURL = [NSData dataWithContentsOfURL:[NSURL URLWithString:searchQuery]];
NSURL *url = [[NSURL alloc] initWithString:searchQuery];
NSURLRequest *request = [[NSURLRequest alloc] initWithURL:url];
// to receive the returend value
NSString *strResult = [[NSString alloc] initWithData:dataURL encoding:NSUTF8StringEncoding];
NSLog(@"strResult: %@",strResult);
NSLog(@"searchQuery: %@", searchQuery);
NSError *error;
self.json2 = [NSJSONSerialization JSONObjectWithData:dataURL
options:kNilOptions
error:&error];
NSDictionary* defineJsonData = [self.json2 lastObject];
NSNumber* surveyID = [defineJsonData objectForKey:@"SurveyID"];
NSLog(@"UserID: %@", surveyID);
NSArray* userQuestions = [defineJsonData objectForKey:@"Question"];
NSLog(@"Question for Survey: %@", userQuestions);