Tôi đang gặp một thời gian khó phân tích cú pháp dưới đây JSON chuỗi trên iOS 5.iOS 5 JSON Parsing Kết quả trong Cocoa Lỗi 3840
{"States": [{"Name": "Arizona","Cities": [{"Name": "Phoenix"}]},{"Name": "California","Cities": [{"Name": "Orange County"},{"Name": "Riverside"},{"Name": "San Diego"},{"Name": "San Francisco"}]},{"Name": "Nevada","Cities": [{"Name": "Las Vegas"}]}]}
Và đây là mã của tôi:
- (void) parseJson {
NSError *jsonError = nil;
NSData *jsonData = [NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"Locations-JSON" ofType:@"rtf"]];
if (jsonData) {
NSDictionary *jsonObjects = [NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingMutableContainers error:&jsonError];
if (jsonError) {
NSLog(@"JSON Error: %@", [jsonError localizedDescription]);
return;
}
NSLog(@"%@", jsonObjects);
}
}
tôi tiếp tục nhận được lỗi này:
JSON Error: The operation couldn’t be completed. (Cocoa error 3840.)
tôi đánh giá cao sự giúp đỡ về vấn đề này bởi vì tôi cl sớm và không có khả năng sửa lỗi này.
Liệu nó thành công thiết jsonData? –