0

Created a NSMutableDictionary object that need to pass as a request parameter in web service. Took all the keys and values of string type.

-(void)createPayload {
    NSMutableDictionary *payload = [[NSMutableDictionary alloc]init];
    [payload setObject:@"T1" forKey:@"table_no"];
    [payload setObject:@"18.05" forKey:@"total_amount"];
    [payload setObject:@"3759121" forKey:@"order_id"];
    [payload setObject:@"INR" forKey:@"currency_code"];
    [payload setObject:@"VISA" forKey:@"paymentType"];
    [payload setObject:@"54ds5sds6fhhh56" forKey:@"resturent_id"];
    [payload setObject:@"ios" forKey:@"mode"];
    
    NSMutableDictionary *paramDict = [[NSMutableDictionary alloc]init];
    [paramDict setObject:payload forKey:@"payload"];
    NSLog(@"Parameter dictionary:\n%@",paramDict);
    //[self checkDataTypeOfDisctionaryObjects:payload];
}

Actual Output -

{
     payload =     {
         "currency_code" = INR;
         mode = ios;
         "order_id" = 3759121;
         paymentType = VISA;
         "resturent_id" = 54ds5sds6fhhh56;
         "table_no" = T1;
         "total_amount" = "18.05";
     };
 }

Expected Output -

{
    "payload" =     {
        "currency_code" = "INR";
        "mode" = "ios";
        "order_id" = "3759121";
        "paymentType" = "VISA";
        "resturent_id" = "54ds5sds6fhhh56";
        "table_no" = "T1";
        "total_amount" = "18.05";
    };
 }
 

But when printing logs or sending to web service only few keys and values are showing string type remaining changed into other type. My web service assuming keys and values those are inside double quote("") are string type. If any key and value do not have double quote("") web service is throwing error.

  • My question is why all the keys and values do not have double quote("")? All should be same.
    Note - If we check keys and values using isKindOfClass: will return string type. Same output in swift as well.
Dipak
  • 2,263
  • 1
  • 21
  • 27
  • 4
    Don't worry, it's an "log". In fact, `description` method will not add double quotes when it's obviously a string. Well, obviously having its own logic. It's a string, with only alpha characters. So if there is a "_", it will add the double quotes, etc. – Larme Jun 30 '21 at 11:03
  • 1
    Related: https://stackoverflow.com/questions/65719435/swift-codable-protocol-string-encoding-issue/65719619 – Sweeper Jun 30 '21 at 11:03
  • Maybe check also that https://github.com/gnustep/libs-base/blob/master/Source/NSDictionary.m ? and it's `description` override. – Larme Jun 30 '21 at 11:07
  • Thanks @Larme and Sweeper got your point and understood logic behind double quote. There was some issue in web service because of that getting error and creates doubt on payload but payload was correct. – Dipak Jul 02 '21 at 15:41
  • If you use JSON for instance and "do it yourself", print the JSON you send to be sure, print the real payload there. – Larme Jul 02 '21 at 15:45
  • @Larme verified that way also. Now and onward will trust on JSON only☺️ – Dipak Jul 02 '21 at 15:47

0 Answers0