成功连接到服务器但在json格式字符串后得到了一些废话

时间:2013-04-02 02:57:07

标签: ios xcode json nsurlrequest nsmutableurlrequest

我已成功连接到服务器,并从中获取正确的json格式字符串。不知何故,它有十分之九的时间返回了一些额外的东西..就像一些我不认识的废话代码。有时它只是不完整的数据。我想知道我做错了什么或我做了什么......

有没有人有同样的问题?我该如何解决?

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;

0 个答案:

没有答案