2014-11-06 2 views
0

웹 서비스에서 응답을 받았습니다. 어제는 nil JSON을 받기 시작했으나 응답에서 적절한 바이트 데이터를 가지고 있습니다.JSON 응답이 iPhone에 0을 표시합니다.

여기 내 코드입니다 :

NSDictionary *jsonDict = [NSJSONSerialization JSONObjectWithData:byteData options: NSJSONReadingMutableContainers error:&error]; 
NSLog(@"jsonDict %@",jsonDict); 

byteData이 전무 아니라, jsonDict은 전무하다. 내 코드가 갑자기 작동하지 않습니다. 여기 나는 서비스에서 얻고 있다는 응답 :

{"DecryptDocAndCreatePDFResult":"abcdhdsgs"} 

감사합니다, 제발 도와주세요.

+1

로그'error'을 확인합니다. 그것은 무엇을 말하는가? – rmaddy

+1

이 코딩은 훌륭합니다, show ur NSLog (@ "jsonDict % @", jsonDict); –

+0

로그 오류입니다 - 오류 도메인 = NSCocoaErrorDomain 코드 = 3840 "작업을 완료 할 수 없습니다 (코코아 오류 3840)."JSON 텍스트가 배열 또는 개체 및 옵션으로 조각이 설정되지 않도록 할 수 없습니다. UserInfo = 0x7872cf50 {NSDebugDescription = 파편이 설정되지 않도록 JSON 텍스트가 배열이나 객체 및 옵션으로 시작되지 않았습니다.} – Nancy

답변

0

먼저 JSON이다가 오는 것을 확인 여부를

NSString *tmp=[[NSString alloc]initWithData:byteData encoding:NSUTF8StringEncoding]; 

NSLog(@"before %@", tmp); 


after that start your 

NSDictionary *jsonDict = [NSJSONSerialization JSONObjectWithData:byteData options: NSJSONReadingMutableContainers error:&error]; //  try this NSJSONReadingMutableContainers into NSJSONReadingAllowFragments 
NSLog(@"jsonDict %@",jsonDict); 

NSJSONReadingOptions의 몇 가지 유형이

typedef NS_OPTIONS(NSUInteger, NSJSONReadingOptions) { 
NSJSONReadingMutableContainers = (1UL << 0), 
NSJSONReadingMutableLeaves = (1UL << 1), 
NSJSONReadingAllowFragments = (1UL << 2) 
KNilOptions // I added here 
}; 
+0

먼저 o/p가 오는지 여부를 확인하십시오. NSLog (@ "before % @", tmp); –

+0

좋은 하루 되십시오. 내 친구 –

0

먼저 json으로 변환하기 전에 먼저 모두 해제하십시오. 있는 NSString O/P에게

NSString *strResponce=[[NSString alloc]initWithData: byteData encoding:NSUTF8StringEncoding]; 
NSLog(@"%@",strResponce); 
+0

이 질문에 대한 답변이 아닙니다. – rmaddy