【发布时间】:2014-12-31 06:05:41
【问题描述】:
我检查了我的代码,但没有发现我的代码有什么问题..我正在使用 post 方法进行 JSON 解析。同样的代码在 Xcode 5 中工作,但在 Xcode 6 中不起作用。在我的JSON序列化。
parsingResultLogin = {
"error_code" = "-1";
"error_message" = "";
}
我的代码是 -
-(void)loginFromServer
{
NSString *strURL = [NSString stringWithFormat:@"%@login",GLOBALURLDOMAIN];
NSLog(@"strURL =%@",strURL);
NSData *dataPostLogin = nil;
NSDictionary *dicPostDataLogin = [ NSDictionary dictionaryWithObjectsAndKeys:@"qwertyuiopwqq",@"username",@"qwertyuiop",@"password",@"1234567890987654",@"device_token",@"ios",@"device_type", nil];
NSLog(@"%@",[dicPostDataLogin description]);
dataPostLogin = [NSJSONSerialization dataWithJSONObject:dicPostDataLogin options:NSJSONWritingPrettyPrinted error:nil];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:strURL] cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:60];
NSLog(@"request = %@",request);
[request setHTTPBody:dataPostLogin];
[request setHTTPMethod:@"POST"];
[request setValue:[NSString stringWithFormat:@"%lu",(unsigned long)[dataPostLogin length]] forHTTPHeaderField:@"Content-Length"];
[request setValue:@"JSON/application" forHTTPHeaderField:@"Content-Type"];
NSData *responseData = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
NSLog(@"responsedata =%@",responseData);
if (responseData == NULL) {
AppDelegate *appdel = [[UIApplication sharedApplication]delegate];
[appdel alertError];
}
else
{
NSDictionary *parsingResultLogin = [NSJSONSerialization JSONObjectWithData:responseData options:0 error:nil];
NSLog(@"parsingResultLogin = %@",parsingResultLogin);
//NSString *strParseDataResult = [parsingResultLogin objectForKey:@""];
}
}
【问题讨论】:
标签: objective-c ios7 xcode5 xcode6