用处:把用户输入的表单值放入字典,字典在转json传
方法:
+ (NSString*)jsonFromDictionary:(NSDictionary*)dict
{
NSData* jsonData = [NSJSONSerialization dataWithJSONObject:dict options:0 error:nil];
return [[NSString alloc] initWithBytes:[jsonData bytes] length:[jsonData length] encoding:NSUTF8StringEncoding];
}
用法:
NSDictionary* curBank = cgyhArr[currentCGXYView.tag];
NSMutableDictionary* dictcg = [[NSMutableDictionary alloc] init];
[dictcg setValue:_inputValues[2] forKey:@"YHZH"];
[dictcg setValue:_inputValues[3] forKey:@"YHMM"];
[dictcg setValue:@"1" forKey:@"ZZHBZ"];//指定行币种
[dictcg setValue:@"1" forKey:@"BZ"];//币种
[dictcg setValue:[curBank valueForKey:@"YHDM" ] forKey:@"YHDM"];//银行代码
NSMutableDictionary* dictxy = [[NSMutableDictionary alloc] init];
[dictxy setValue:[curBank valueForKey:@"XYID" ] forKey:@"HTXY"];//合同协议
[dictxy setValue:@"" forKey:@"XYBH"];//协议编号
[dictxy setValue:qmlsh forKey:@"QMLSH"];//签名流水号
NSMutableDictionary* json = [[NSMutableDictionary alloc] init];
[json setValue:@[dictcg] forKey:@"CGYHSTR"];
[json setValue:@[dictxy] forKey:@"CGXYSTR"];
if (_isReAssign) {
[json setValue:[_khzt valueForKey:@"bdid"] forKey:@"BDID"];
}
return [SSUtility jsonFromDictionary:json];