iOS 字典转JSON字符串

    NSMutableDictionary *dic = [[NSMutableDictionary alloc]init];

    

    [dic setValue:@"2660" forKey:@"userId"];

    [dic setValue:@"2660" forKey:@"cardid"];

    [dic setValue:@"2660" forKey:@"cardcity"];

    [dic setValue:@"2660" forKey:@"cardtype"];

    [dic setValue:@"UnBindCard" forKey:@"txncode"];

    [dic setValue:@"00" forKey:@"idType"];

    

    [dic setValue:@"2660" forKey:@"idName"];

    [dic setValue:@"2660" forKey:@"idNo"];

    [dic setValue:@"2660" forKey:@"email"];

    [dic setValue:@"2660" forKey:@"mobile"];

转化前:

Printing description of dic:

{

    cardcity = 2660;

    cardid = 2660;

    cardtype = 2660;

    email = 2660;

    idName = 2660;

    idNo = 2660;

    idType = 00;

    mobile = 2660;

    txncode = UnBindCard;

    userId = 2660;

}


    NSData *data=[NSJSONSerialization dataWithJSONObject:dic options:NSJSONWritingPrettyPrinted error:nil];

    NSString *jsonStr=[[NSString alloc]initWithData:data encoding:NSUTF8StringEncoding];

    

    NSLog(@"jsonStr is %@",jsonStr);


转化后:

Printing description of jsonStr:

{

  "idType" : "00",

  "idName" : "2660",

  "userId" : "2660",

  "cardid" : "2660",

  "mobile" : "2660",

  "cardtype" : "2660",

  "idNo" : "2660",

  "email" : "2660",

  "txncode" : "UnBindCard",

  "cardcity" : "2660"

}




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值