Swift: dictionaries inside array

前端 未结 4 854
半阙折子戏
半阙折子戏 2021-01-16 04:08

Data:

[
    { firstName: \"Foo\", lastName: \"Bar\" },
    { firstName: \"John\", lastName: \"Doe\" }
]

How can I have this kind of structu

4条回答
  •  孤街浪徒
    2021-01-16 04:23

    something like this can work for you:

    var persons: Array> = Array()
    

    and now you can add the names:

    persons.append(["firstName": "Foo", "lastName": "Bar"]);
    persons.append(["firstName": "John", "lastName": "Doo"]);
    

    NOTE: if you are insecure how to use literals, just don't use them.

提交回复
热议问题