json 类型

1.生成json字符串json

NSData * jsonData = [NSJSONSerialization dataWithJSONObject:detailDic options:0 error:nil];  
NSString * myString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];

2.json解析code

NSDictionary * selectSimpleTest = [NSJSONSerialization JSONObjectWithData:[tizhiSimpleTest.detail dataUsingEncoding:NSUTF8StringEncoding] options:0 error:nil];

3.字典转化成json 类型字符串

+(NSString *)JsonModel:(NSDictionary *)dictModel
{
    if ([NSJSONSerialization isValidJSONObject:dictModel])
    {
        NSData * jsonData = [NSJSONSerialization dataWithJSONObject:dictModel options:NSJSONWritingPrettyPrinted error:nil];
        NSString * jsonStr = [[NSString alloc]initWithData:jsonData encoding:NSUTF8StringEncoding];
        return jsonStr;
    }
    return nil;
}
相关文章
相关标签/搜索