1

I have a JSON dictionary that looks like this:

{
"111": {"dates"   : [<array_of_dates>], 
        "members" : [<array_of_members>]}, 
"112": {"dates"   : [<array_of_dates>], 
        "members" : [<array_of_members>]},
"113": {"dates"   : [<array_of_dates>], 
        "members" : [<array_of_members>]}
}

As you can see, the key for the nested dictionary is variable (111, 112, 113).

So far, every Mantle model I have made has fixed keys so I don't know how to handle this particular situation.

Any ideas?

4

1 回答 1

1

you have several options:

  • change server side API to return this dictionary nested in a key ({"property": { "111": …, "222": … }}) so you can actually bind to it
  • modify response on the client prior to parsing

Once you have a value you can pass use in +JSONKeyPathsByPropertyKey, you can write a custom value transformer to process the model.

Here are two examples to get you started:

The most important part is to figure out how do you want to use the map you're getting from JSON. Maybe you're better off by keeping it as a dictionary in a private property and write public methods accessing it in a way that makes sense

于 2015-09-01T18:05:22.133 回答