AFNetworking posts JSON arrays as multiple single-entry dictionaries

前端 未结 4 1602
予麋鹿
予麋鹿 2020-12-19 13:26

I\'m having a similar issue to the one discussed here.

I\'m attempting to post JSON to a server.

Here\'s the Objective-C code that should work, but

4条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-19 14:13

    I too had this issue recently, I had the following parameters to be sent to the server, but the "feature" array was breaking into 4 parts rather than just 2 dictionaries.

            { "description": "Temporary Description",   
              "name": "Product Name",  
              "feature": [
                {
                  "fkey": "FT1",
                  "fvalue": "FD1"
                },
                {
                  "fkey": "FT2",
                  "fvalue": "FD2"
                }   
             ] 
        }
    

    So I changed the

    AFURLRequestSerialisation.m

    replaced this line in AFQueryStringPairsFromKeyAndValue(NSString *key, id value) method

    [mutableQueryStringComponents addObjectsFromArray:AFQueryStringPairsFromKeyAndValue([NSString stringWithFormat:@"%@[]", key], nestedValue)];
    

    with

    [mutableQueryStringComponents addObjectsFromArray:AFQueryStringPairsFromKeyAndValue([NSString stringWithFormat:@"%@[%i]", key, [array indexOfObject:nestedValue]], nestedValue)];
    

    And this did the trick. I hope this might help someone.

提交回复
热议问题