12345678910111213141516171819202122232425262728293031323334353637383940 |
- //
- // ZGJsonUtils.m
- // UUTPM
- //
- // Created by zhuge on 15/1/5.
- // Copyright (c) 2015年 UUT. All rights reserved.
- //
- #import "ZGJsonUtils.h"
- //#import "ZGAlert.h"
- @implementation ZGJsonUtils
- #pragma mark private
- #pragma mark public
- +(id)stringToObject:(NSString *)str {
- NSError *error = nil;
- NSData *data = [str dataUsingEncoding:NSUTF8StringEncoding];
- id ret = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:&error];
- if (error) {
- NSLog(@"JSON ERROR: %@", [error localizedDescription]);
- // [ZGAlert alertWithMessage:[error localizedDescription] window:nil];
- return nil;
- }
- return ret;
- }
- + (NSString *)dictionaryToString:(NSDictionary *)dict {
- NSError *error = nil;
- // NSData *jsonData = [NSJSONSerialization dataWithJSONObject:dict options:NSJSONWritingPrettyPrinted error:&error];
- NSData *jsonData = [NSJSONSerialization dataWithJSONObject:dict options:0 error:&error];
- if (error) {
- NSLog(@"%@", dict);
- NSLog(@"JSON ERROR: %@", [error localizedDescription]);
- // [ZGAlert alertWithMessage:[error localizedDescription] window:nil];
- return nil;
- }
- return [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
- }
- @end
|