在我的应用程序中,我正在与服务器建立连接并尝试JSON
从服务器获取数据。当我发送请求时,JSON
很快就会在服务器中生成一个对象并将其发送回客户端(应用程序)。NULL
但问题是 10 次中有 2 次,即使数据是从服务器发送的,我也在客户端获得价值(不会为所有请求生成NULL data but a
JSON JSON数据)。data since
即使数据是在服务器中生成的,我也不确定为什么我会得到 NULL(通过观察服务器日志,我可以这么说)
代码如下
if(netStatus==ReachableViaWiFi || netStatus==ReachableViaWWAN){
NSURL *url = [NSURL URLWithString:formattedURL];
NSURLRequest* request = [NSURLRequest requestWithURL: url cachePolicy: NSURLRequestReloadIgnoringCacheData timeoutInterval:10.0];
[NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *jsonData, NSError *error)
{
if (error){
}
else{
if ([NSString stringWithUTF8String:[jsonData bytes]]==NULL){
NSLog("The result is NULL");
}
我得到结果有时是NULL。我找不到模式。但这会发生 10 次中的 2 次。我无法确定问题出在服务器还是应用程序上。请告诉我。谢谢你的时间