mantle - How to write value transformer for a dictionary

211 Views Asked by At

I have this response from an API and trying to find ways to map this to an NSDictionary using a Mantle value transformer.

 {
   "baggage": {
    "BAG10": "3.5",
    "BAG15": "3.5",
    "BAG20": "3.5",
    "BAG30": "3.5",
    "BAG40": "3.5"
   }
}

Thanks in advance

2

There are 2 best solutions below

0
melaka On BEST ANSWER

By the looks of it, we don't need to write any transformers for this property. Mantle handles by itself.

0
RunLoop On

You can use NSJSONSerialization passing in the server response as NSData

NSMutableDictionary *dict = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil]