0

我正在解析 iphone 应用程序中的 json 数据。但它没有正确解析它。

我正在使用以下代码:

- (void)getSurveyList {     
       user_id=user_id;        
       NSLog(@"This is uerid %@",user_id);
       NSArray *tempArray =[[DataManager staticVersion] startParsing:@"http://myser-solutions.com/app/surveyList.php?user_id=user_id"];

       for (int i = 0; i<[tempArray count]; i++) {            
          id *item = [tempArray objectAtIndex:i];    
          NSDictionary *dict = (NSDictionary *) item;        
          ObjectData *theObject =[[ObjectData alloc] init];
          [theObject setUser_id:[dict objectForKey:@"user_Id"]];
          [theObject setSurvey_Id:[dict objectForKey:@"survey_Id"]];
          [theObject setSurvey_Name:[dict objectForKey:@"survey_Name"]];
          [theObject setTotal_Question:[dict objectForKey:@"total_Question"]];  
          [theObject setAdministrator_Email:[dict objectForKey:@"administrator_Email"]];
          [theObject setStart_Date:[dict objectForKey:@"start_Date"]];
          [theObject setEnd_Date:[dict objectForKey:@"end_Date"]];      
          [theObject setStatus:[dict objectForKey:@"status"]];    
          [theObject setAdministrator_Email:[dict objectForKey:@"user_Password"]];    
          [surveyList addObject:theObject];    
          [theObject release];
          theObject=nil;            
          int count =[surveyList count];
          NSLog(@"Total is %d",count);               
      }
}

在我调试代码时它不会进入循环。我不知道为什么。

JSON响应

ali40[{"user_Id":"ali40","survey_Id":"1","survey_Name":"Veritas 调查","total_Questions":"20","administrator_Email":"engr.jamshedali@hotmail.com", "start_Date":"20-9-2012","end_Date":"1-10-2012","status":"Active","user_Password":"jackson12"},{"user_Id":"ali40", "survey_Id":"2","survey_Name":"Celeritas 调查","total_Questions":"20","administrator_Email":"jani_06sw@yahoo.com","start_Date":"10-11-2012"," end_Date":"12-12-2012","status":"Active","user_Password":"jackson12"}]

4

2 回答 2

0

如果它没有进入循环,则tempArray必须为空。请再次检查。

于 2012-09-20T06:36:00.103 回答
0

解析可能不正确。临时数组返回 nil。检查解析这是一个很好的教程这里的 SBJSON 三件事要检查

  • 输入 - 正确获取
  • 它是有效的 JSON 响应吗
  • 正确解析
于 2012-09-20T06:59:32.727 回答