/*!
*?@brief?把格式化的JSON格式的字符串轉(zhuǎn)換成字典
*?@param?jsonString?JSON格式的字符串
*?@return?返回字典
*/
+?(NSDictionary?*)dictionaryWithJsonString:(NSString?*)jsonString?{
if(jsonString?==?nil)?{
return nil;
}
NSData?*jsonData?=?[jsonString?dataUsingEncoding:NSUTF8StringEncoding];
NSError?*err;
NSDictionary?*dic?=?[NSJSONSerialization?JSONObjectWithData:jsonData
options:NSJSONReadingMutableContainers
error:&err];
if(err)?{
NSLog(@"json解析失斦胺稹:%@",err);
return nil;
}
return dic;
}
/**
*??字段轉(zhuǎn)換成json字符串
*
*??@param?dict?<#dict?description#>
*
*??@return?<#return?value?description#>
*/
+(NSString?*)dictToJsonStr:(NSDictionary?*)dict{
//????NSMutableDictionary?*dict?=?[NSMutableDictionary?new];
//????[dict?setObject:@""?forKey:@"AWL_LAN"];
//????[dict?setObject:@""?forKey:@"AWL_LON"];
//????[dict?setObject:@"1"??forKey:@"U_ID"];
NSString?*jsonString?=?nil;
if([NSJSONSerialization?isValidJSONObject:dict])
{
NSError?*error;
NSData?*jsonData?=?[NSJSONSerialization?dataWithJSONObject:dict?options:NSJSONWritingPrettyPrinted?error:&error];
jsonString?=[[NSString?alloc]?initWithData:jsonData?encoding:NSUTF8StringEncoding];
//NSLog(@"json?data:%@",jsonString);
if(error)?{
NSLog(@"Error:%@",?error);
}
}
return jsonString;
}