Swift: dictionaries inside array

前端 未结 4 855
半阙折子戏
半阙折子戏 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:31

    The correct way is:

    var persons = [Dictionary]()
    

    which is equivalent to:

    var persons = [[String : String]]()
    

    What your code does instead is to create an array filled in with an instance of Dictionary, whereas I presume you want an empty instance of the array containing elements of Dictionary type.

提交回复
热议问题