RealmSwift-JSON icon indicating copy to clipboard operation
RealmSwift-JSON copied to clipboard

how to parse dictionary within dictionary

Open ordinaryman09 opened this issue 9 years ago • 1 comments

Hi,

How can we parse dictionary within dictionary? Suppose you have key1 : val1, key2 : { test1 : valtest1 test2 : valtest2 }

from Matthew's Realm-JSON, I can do like

  • (NSDictionary *)JSONInboundMappingDictionary { return @{ @"key1": @"key1", @"key2.test1": @"test1", @"key2.test2": @"test2" }

Do we have something similar with yours? Thanks!

ordinaryman09 avatar Jul 08 '16 00:07 ordinaryman09

Hello ordinaryman09 Thank you for suggesting the issue.

Unfortunately, RealmSwift-JSON doesn't support the way that you mentioned like key2.test.

But if you make models which inherit Object, you could use like the way that you want.

Here is the example of your case.

class Model1:Object {
dynamic var key1:String?
dynamic var key2:Model2?
}
class Model2:Object {
dynamic var test1:String?
dynamic var test2:String?
}

and then you don't need to implement JSONInboundMappingDictionary it would be implemented automatically.

I wish it would help you.

Changsung avatar Jul 15 '16 02:07 Changsung