[英]JSON response showing nil in iPhone
I am getting a response from a webservice. 我正在从Web服务获得响应。 Yesterday I started getting nil JSON, but from response I am have proper byte data.
昨天我开始获取nil JSON,但是从响应中我有正确的字节数据。
Here is my code: 这是我的代码:
NSDictionary *jsonDict = [NSJSONSerialization JSONObjectWithData:byteData options: NSJSONReadingMutableContainers error:&error];
NSLog(@"jsonDict %@",jsonDict);
byteData is not nil, but jsonDict is nil. byteData不是nil,但是jsonDict是nil。 My code is not working suddenly.
我的代码突然无法正常工作。 Here the response that I am getting from the service :
这是我从服务获得的响应:
{"DecryptDocAndCreatePDFResult":"abcdhdsgs"}
Please help me, Thanks. 请帮助我,谢谢。
First off all before convert to the json. 首先转换为json。 check the NSString O/p
检查NSString O / p
NSString *strResponce=[[NSString alloc]initWithData: byteData encoding:NSUTF8StringEncoding];
NSLog(@"%@",strResponce);
first check that your JSON
is comes or not 首先检查您的
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);
the some type of NSJSONReadingOptions
is NSJSONReadingOptions
的某种类型是
typedef NS_OPTIONS(NSUInteger, NSJSONReadingOptions) {
NSJSONReadingMutableContainers = (1UL << 0),
NSJSONReadingMutableLeaves = (1UL << 1),
NSJSONReadingAllowFragments = (1UL << 2)
KNilOptions // I added here
};
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.