在进行网络请求是需要用到特定格式的字符串,比如post请求时的接口格式如下:http://mobile.ximalaya.com/mobile/track/comment?device=android&pageSize=15&pageId=2&trackId=1234

将写好的字典转换成这种格式的方法:

//将字典转换成字符串 key=value&key=value&key=value

- (NSString *)_parseDictionaryToFormattedString:(NSDictionary *)dic

{

NSMutableArray *tempArray = [NSMutableArray array];

NSArray *keyArray = [dic allKeys];

for (NSString *key in keyArray) {

NSString *valueString = [dic objectForKey:key];

NSString *formattedString = [NSString stringWithFormat:@"%@=%@", key, valueString];

[tempArray addObject:formattedString];

}

NSString *finalString = [tempArray componentsJoinedByString:@"&"];

return finalString;

}