NSMutableArray 转 json

             NSMutableArray *arr = [[NSMutableArray alloc] init];
           
                    
            
            
            NSDictionary *params = [NSDictionary dictionaryWithObjectsAndKeys:
                                    @"ni hao", @"key",
                                    @"45", @"value",
                                    @"USD", @"code",nil];
            
            NSDictionary *params2 = [NSDictionary dictionaryWithObjectsAndKeys:
                                    @"hao", @"key",
                                    @"45", @"value",
                                    @"USD", @"code",nil];
            
            
            [arr addObject:params];
            [arr addObject:params2];
            
         

            
          
            
            NSDictionary *params3 = [NSDictionary dictionaryWithObjectsAndKeys:
                                      arr, @"json",
                                     nil];

            
            //convert object to data
            NSData* jsonData =[NSJSONSerialization dataWithJSONObject:params3
                                                              options:NSJSONWritingPrettyPrinted error:&error];  
            
            //print out the data contents  
            NSString* text =[[NSString alloc] initWithData:jsonData
                                                    encoding:NSUTF8StringEncoding];  
            
            
            
            NSLog(@"json字典里面的内容为--》%@", text );

你可能感兴趣的:(NSMutableArray 转 json)