iOS 字典转JSON字符串

    xiaoxiao2021-04-13  33

        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"

    }

    转载请注明原文地址: https://ju.6miu.com/read-669324.html

    最新回复(0)