Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/clojure/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 成功连接到服务器,但json格式字符串后出现了一些问题_Ios_Xcode_Json_Nsurlrequest_Nsmutableurlrequest - Fatal编程技术网

Ios 成功连接到服务器,但json格式字符串后出现了一些问题

Ios 成功连接到服务器,但json格式字符串后出现了一些问题,ios,xcode,json,nsurlrequest,nsmutableurlrequest,Ios,Xcode,Json,Nsurlrequest,Nsmutableurlrequest,我已成功连接到服务器,并从中获取正确的json格式字符串。不知怎的,10次中有9次是带着额外的东西回来的。。就像一些我不认识的垃圾代码。有时它只是不完整的数据。我想知道我做错了什么或我没有做什么 有人有同样的问题吗?我怎样才能修好它 NSURL *siteURL = [NSURL URLWithString:tempSiteString]; NSMutableURLRequest *request = [[NSMutableURLRequest alloc]

我已成功连接到服务器,并从中获取正确的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;

您能否通过在iOS应用程序外部访问此JSON API来复制错误的JSON数据?可能是服务器端的问题。@顺便说一句,您提供的信息不完整。请提供从服务器收到的垃圾样本数据。这样任何人都可以帮忙you@stuar不,在安卓系统上它没有发生…@RamuPasupuleti这种垃圾不会经常发生。。。我刚刚发现它不是不完整的数据。。。它在json格式结束后重复json文件的一部分…@supermantoby,实现NSURL连接委托方法并等待数据加载。如果垃圾只是重复了几次,可能是服务器端的问题。