-3
向.NET服务器发送请求无法正常工作。JSON在iOS中发布无法正常工作(.NET服务器)
NSDictionary *jsonDict = [NSDictionary dictionaryWithObjects:objects forKeys:keys];
NSURL *postURL = [NSURL URLWithString: @"SOME URL"];
NSError *error=nil;
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:jsonDict options:0 error:&error];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL: postURL
cachePolicy: NSURLRequestUseProtocolCachePolicy
timeoutInterval: 60.0];
[request setHTTPMethod: @"POST"];
[request setValue: @"application/json" forHTTPHeaderField: @"Accept"];
[request setValue: @"application/json" forHTTPHeaderField: @"Content-Type"];
[request setValue:[NSString stringWithFormat:@"%d",[jsonData length]] forHTTPHeaderField:@"Content-Length"];
[request setHTTPBody: jsonData];
NSLog(@"JSON summary: %@", [[NSString alloc] initWithData:jsonData
encoding:NSUTF8StringEncoding]);
输出为:
{"CreatedBy":"","EmailAddress":"[email protected]","Zipcode":"","FirstName":"devan","DeviceCategoryID:":"","State":"","CustomerTypeID:":"",..........} like this.....
但JSON对象必须是:
({CreatedBy:"",EmailAddress:"[email protected]",Zipcode:"",FirstName:"devan",DeviceCategoryID::"",State:"",CustomerTypeID:"" })
我使用.NET服务器张贴。
请求不会发送到服务器。任何人都请帮助我。
输出看起来正确。请花10分钟时间学习[JSON格式](http://www.json.org)。如果你无法在服务器端解析这个json,那么问题在于别处。 – Mar0ux 2013-05-03 11:05:46
你总是可以使用http://json.parser.online.fr/来验证你的输出。 – Mar0ux 2013-05-03 11:07:02