iOS 把字典转为Json

    NSMutableArray *array = [NSMutableArray array];
    NSDictionary *dict = @{@"productId": @"P0000002",@"count":@1,@"price":@50};
    [array addObject:dict];
    NSError *error;
    NSData *jsonData = [NSJSONSerialization dataWithJSONObject:array options:NSJSONWritingPrettyPrinted error:&error];
    NSString *jsonString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];

    NSMutableDictionary *parameters = [NSMutableDictionary dictionary];
    parameters[@"areward"] = jsonString;

你可能感兴趣的:(iOS 把字典转为Json)