Monday, September 23, 2013

ios json resolution issues


 NSURL * url = [NSURL URLWithString: @ "http://192.168.1.101/website1/studentinfo.ashx?sno=sno20130811002"];  NSError * error;  NSURLRequest * request = [NSURLRequest requestWithURL: url];  NSData * data = [NSURLConnection sendSynchronousRequest: request returningResponse: nil error: nil];  NSDictionary * dic = [NSJSONSerialization JSONObjectWithData: data options: NSJSONReadingMutableLeaves error: & error];  NSDictionary * dic_student = [dic objectForKey: @ "StudentInfo"];  NSLog (@ "Result:% @", dic_student);  


Print Dictionary dic_student output:
Result: (
{
Sage = 23;
Sdept = "\ U73af \ U5883 \ U5de5 \ U7a0b";
Sname = zhanghuan;
Sno = SNO20130811002;
Spec = "\ U73af \ U5883 \ U5b89 \ U5168";
Ssex = "\ U7537";
}
)
At this point the keys inside the dictionary dic_student why not visit? Dictionaries allKeys is empty, inside the school number and names of attributes not visit

Reply:
Make sure your JSON data format is not valid.
Here can be copied to verify: http://jsonlint.com/
Reply:
Playing out on the json
Reply:
 
NSArray * dic_student_array = [dic objectForKey: @ "StudentInfo"];
NSDictionary * dic_student = [dic_student_array objectAtIndex: 0];


Try to change the next, JSON data watching, StudentInfo is an array ...

No comments:

Post a Comment