我已成功连接到服务器,并从中获取正确的 json 格式字符串。不知何故,10 次中有 9 次返回一些额外的东西......就像一些我不认识的废话代码。有时它只是不完整的数据。我想知道我做错了什么或我没有做什么..
有没有人有同样的问题?我该如何解决?
NSURL *siteURL = [NSURL URLWithString:tempSiteString];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc]
initWithURL:siteURL
cachePolicy:NSURLRequestReloadIgnoringLocalCacheData
timeoutInterval:30.0];
NSString *myRequestString = [NSString stringWithFormat:@"data=%@", sqlString];
NSData *myRequestData = [NSData dataWithBytes:[myRequestString UTF8String] length:[sqlString length]];
[request setHTTPMethod: @"POST" ];
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"content-type"];
[request setHTTPBody: myRequestData ];
NSURLResponse *response;
NSError *error;
NSData *returnData = [NSURLConnection sendSynchronousRequest: request
returningResponse: &response
error: &error];
NSString *content = [NSString stringWithUTF8String:[returnData bytes]];
这是我将接收到的字符串更改为 json 的代码
NSDictionary *tempNSDictionary = [resultString JSONValue];
if(tempNSDictionary.count==0)
{
return nil;
}
//NSLog(@"Check Point after dictionary");
NSArray *tempNSArray;
if(tempNSDictionary)
{
//NSLog(@"Check Point getArrayFromJsonString 1");
tempNSArray = [tempNSDictionary objectForKey:@"object_name"];
//NSLog(@"Check Point getArrayFromJsonString 2");
}
return tempNSArray;