0

I am parsing json data in iphone application. But it is not parsing it correct.

I am using the following code:

- (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);               
      }
}

It does not enter in the loop while I debug the code. And I don't know why.

JSON RESPONSE

ali40[{"user_Id":"ali40","survey_Id":"1","survey_Name":"Veritas Survey","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 Survey","total_Questions":"20","administrator_Email":"jani_06sw@yahoo.com","start_Date":"10-11-2012","end_Date":"12-12-2012","status":"Active","user_Password":"jackson12"}]

Shahzad CR7
  • 125
  • 1
  • 1
  • 6

2 Answers2

0

If it is not entering in the loop then tempArray must be empty. Please check once again.

parilogic
  • 1,147
  • 9
  • 26
0

The parsing may be incorrect.The temp array is returned nil.Check on the parsing Here is a nice tutorial and on SBJSON here Three things to check on

  • Input -Fetched properly
  • Is it valid JSON response
  • Properly parsed
Community
  • 1
  • 1
Lithu T.V
  • 19,955
  • 12
  • 56
  • 101