0

This is the result dictionary getting when I converted the Dictionary<AnyHashable, Any> to Dictionary<String, Any>,

{
    "payload":"{\"type_nm\":\"Test\",\"crcd_dt\":{\"date\":\"2020-06-03T09:44:27.211Z\"},\"read\":false,\"crdt_by\":1001,\"org_id\":50581,\"ent_no\":30599}",
    "message":"Push Notification",
    "google.c.sender.id":"1234567890",
    "timestamp":"1591177467211",
    "title":"Test1",
    "aps":{
             "alert":{
                "title":"App Push Notification",
                "body":"Testing the push notification feature"
             },
             "sound":"default",
             "mutable-content":"1"
          }
    },
    "gym.message_id":"9876543210",
    "is_background":"false"
 }

The problem here is, the value of payload key is also a Dictionary, but I'm getting it as String after conversion. I did the following steps for conversion,

  let hashableDictionary: [AnyHashable: Any] = [:]
  var normalDictionary: Dictionary<String, Any> = [:]
  for (key, value) in hashableDictionary {
     normalDictionary[key.description] = value
  }

Now, normalDictionary prints as above.

Note: Consider hashableDictionary getting from some server, which is of type Dictionary<AnyHashable, Any>.

I need the payload value as Dictionary instead of String, please help to fix this.

Harsha
  • 760
  • 1
  • 7
  • 21

0 Answers0