#pragma mark - dic/array转为jsonString(NSJSONSerialization解析)
/**
* @author zm
*
* @brief dic/array转为jsonString(NSJSONSerialization解析)
*
* @param theData dic/array
*
* @return jsonString
*/
- (NSString *)f_toJSONString:(id)theData{
NSString *_str_json =nil;
if (theData) {
if ([theData isKindOfClass:[NSDictionary class]] || [theData isKindOfClass:[NSMutableDictionary class]] || [theData isKindOfClass:[NSArray class]] || [theData isKindOfClass:[NSMutableArray class]]) {
NSData *_data_json = [NSJSONSerialization dataWithJSONObject:theData
options:NSJSONWritingPrettyPrinted
error:nil];
if (_data_json) {
_str_json = [[NSString alloc] initWithData:_data_json
encoding:NSUTF8StringEncoding];
}
}
}
return _str_json;
}
#pragma mark jsonString转为NSMutableDictionary(NSJSONSerialization解析)
/**
* @author zm
*
* @brief jsonString转为NSMutableDictionary(NSJSONSerialization解析)
*
* @param theData dic/array
*
* @return jsonString
*/
- (NSMutableDictionary *)f_jsonDataToDic:(NSData*)jsonData option:(NSJSONReadingOptions)option
{
NSError *_err_temp;
if(jsonData)
{
NSMutableDictionary *_muDic_json = [NSJSONSerialization
JSONObjectWithData:jsonData
options:option error:&_err_temp];
if(_muDic_json && _muDic_json.count >0)
{
return _muDic_json;
}
}
return nil;
}