2014-11-06 40 views
0

我收到来自web服务的响应。昨天我开始没有JSON,但从响应我有正确的字节数据。在iPhone中显示为零的JSON响应

这里是我的代码:

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

byteData不是零,但jsonDict为零。 我的代码没有突然工作。 这里的响应,我从服务获得:

{"DecryptDocAndCreatePDFResult":"abcdhdsgs"} 

请帮助我,谢谢。

+1

登录'error'。它说什么? – rmaddy 2014-11-06 05:09:39

+1

这种编码很好,显示你的NSLog(@“jsonDict%@”,jsonDict); – 2014-11-06 05:13:47

+0

日志错误是 - 错误域= NSCocoaErrorDomain代码= 3840“操作无法完成。(可可错误3840.)”(JSON文本没有开始数组或对象和选项允许片段没有设置。)UserInfo = 0x7872cf50 {NSDebugDescription = JSON文本没有以数组或对象开始,选项允许片段未设置。 – Nancy 2014-11-06 05:14:19

回答

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(@“%@”,tmp之前); – 2014-11-06 05:25:04

+0

有一个愉快的一天我的朋友 – 2014-11-06 06:58:42

0

首先将所有转换为json。检查的NSString O/P

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

这不是问题的答案。 – rmaddy 2014-11-06 05:27:48