美文网首页
data转json

data转json

作者: 精神薇 | 来源:发表于2018-10-08 16:29 被阅读0次

    demo

    +(NSString*)DataTOjsonString:(id)object
    {
        NSString *jsonString = nil;
        NSError *error;
        NSData *jsonData = [NSJSONSerialization dataWithJSONObject:object
                                                           options:NSJSONWritingPrettyPrinted // Pass 0 if you don't care about the readability of the generated string
                                                             error:&error];
        if (! jsonData) {
            NSLog(@"Got an error: %@", error);
        } else {
            jsonString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
        }
        return jsonString;
    }
    

    相关文章

      网友评论

          本文标题:data转json

          本文链接:https://www.haomeiwen.com/subject/pajjaftx.html