Ios 如何将JSON作为主体发送到请求而不是XMLC
我之前是以正文形式发送xml文件的,声明如下:Ios 如何将JSON作为主体发送到请求而不是XMLC,ios,objective-c,xml,json,http,Ios,Objective C,Xml,Json,Http,我之前是以正文形式发送xml文件的,声明如下: [[NSString stringWithFormat:@"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><vs:ClientID version=\"0.4\" xmlns:vs=\"http://www.@@@@@@.com/schemas/store\">%@</vs:ClientID>", openUDID] UTF8String
[[NSString stringWithFormat:@"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><vs:ClientID version=\"0.4\" xmlns:vs=\"http://www.@@@@@@.com/schemas/store\">%@</vs:ClientID>", openUDID] UTF8String];
[[NSString stringWithFormat:@“%@”,openUDID]UTF8String];
现在我需要为请求发送与JSON相同的正文。
如何实现这一点?您可以通过创建一个要发送的数据字典来实现这一点
NSMutableDictionary *reqDictionary = [[NSMutableDictionary alloc]init];
[reqDictionary setValue:@"yourValue1" forKey:@"YourKey1"];
[reqDictionary setValue:@"yourValue2" forKey:@"YourKey2"];
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:fieldsArray options:NSJSONWritingPrettyPrinted error:&error];
NSString *jsonString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
现在jsonString是您要发布的最后一个字符串