码迷,mamicode.com
首页 > 移动开发 > 详细

iOS:数据转json对象

时间:2015-04-30 12:36:23      阅读:146      评论:0      收藏:0      [点我收藏+]

标签:ios   json   对象   

//封装的转换方法,直接传入你需要转换的数据
- (NSString *)getJsonFromData:(id)sender
{
    //json对象
    NSString *jsonStr;
    //将传进来的数据转换为data
    NSData *jsonData = [NSJSONSerialization dataWithJSONObject:sender options:NSJSONWritingPrettyPrinted error:nil];
    //数据安全判断
    if (jsonData) {
        jsonStr = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
    }else{
        NSLog(@"Get data is nil");
    }
    return jsonStr;
}

iOS:数据转json对象

标签:ios   json   对象   

原文地址:http://blog.csdn.net/u013243469/article/details/45392469

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!