Handling duplicate key values in swift dictionary

Viewed 2655

I have to comply with a Restful request call using Swift 3 that unfortunately contains duplicate keys as shown below. I originally placed the data in a dictionary to pass into a JSON serialization call.

       [
          "mid":"3",
          "attributes":[
                "carID":["a":54123,"b":424,"c":"13242"],
                "update":"true"
                "update":"gold" 
          ]
        ]

Notice that update occurs twice, which causes this error:

fatal error: Dictionary literal contains duplicate keys

I've reviewed this question but doesn't seem to have a pertinent answer.

I thought about using an array but I think it would lose the key value pair relationship that I need for the JSON serialization.

I've seen some articles on using structs but I'm not sure that would address the duplicate key issue

Any recommendations? I'm unable to change the parameter names in the request as it is a third party product.

BTW, I don't think my question is a duplicate of How to avoid duplicate key error in swift when iterating over a dictionary – Ssswift. That example should truly be a struct/class since it is one key value pair (age:age value) that should be in a class or struct. My example has a repeating key with each of the two instances of the repeating key having different meanings (should they update, and what the updated member type should be). I don't see how it would be applicable but am open to enlightenment on it.

Thanks

0 Answers
Related