2013-04-12 39 views
0

我有我試圖解析爲下面看到JSON使用NSJSONSerialization從JSON文件返回一個空數組

-(void)loadSuraNames 
{ 
NSURL * url = [NSURL URLWithString:@"http://www.submission.ws/downloads/json/"]; 

url = [url URLByAppendingPathComponent:@"quran_main.json"]; 

NSURLRequest *request = [NSURLRequest requestWithURL:url]; 
NSData *response = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil]; 

NSError *jsonParsingError = nil; 
NSArray *array = [NSJSONSerialization JSONObjectWithData:response options:0 error:&jsonParsingError]; 

NSLog(@"my Json is empty :(%@", array); 
} 

一個JSON文件,但我沒有得到任何數據傳回解析。任何人都有什麼想法是什麼問題?

我收到以下錯誤:

錯誤域= NSCocoaErrorDomain代碼= 3840「操作無法完成(可可錯誤3840)」(約278字的無效轉義序列)的UserInfo = 0xa47ff60 {字符周圍= NSDebugDescription無效的轉義序列278}

+1

是什麼錯誤告訴你嗎?什麼是你回來的數據? – quellish

+0

錯誤域= NSCocoaErrorDomain代碼= 3840「無法完成操作(可可錯誤3840.)」(字符278周圍的無效轉義序列)。UserInfo = 0xa47ff60 {NSDebugDescription =字符278周圍的無效轉義序列。} –

+1

看起來像你有一些不好的數據。永遠記住使用NSError的推薦方式 - 請參閱https://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/ErrorHandlingCocoa/CreateCustomizeNSError/CreateCustomizeNSError.html#//apple_ref/doc/uid/TP40001806-CH204 -SW1 – quellish

回答

1

的JSON腳本加入我手動刪除「/」字符和問題走了:)