admin管理员组文章数量:1399313
I am using Alamofire for API call
Actual response, when I call api in browser or POSTMAN:
{
"code": 200,
"message": "Listing found.",
"data": [
{
"_id": "67c5596998c649dfa0d45a48",
"tableData": [
{
"Name": "Mose Boyle",
"Email": "[email protected]",
"Phone": "309.534.1394"
}
]
}
]
}
But when I call in my iOS response this happens
{
"code": 200,
"message": "Listing found.",
"data": [
{
"_id": "67c5596998c649dfa0d45a48",
"tableData": [
{
"Email": "[email protected]",
"Phone": "309.534.1394",
"Name": "Mose Boyle"
}
]
}
]
}
Position randomly changes.
Keys are dynamic so I can't create the model for that.
I am using Alamofire for API call
Actual response, when I call api in browser or POSTMAN:
{
"code": 200,
"message": "Listing found.",
"data": [
{
"_id": "67c5596998c649dfa0d45a48",
"tableData": [
{
"Name": "Mose Boyle",
"Email": "[email protected]",
"Phone": "309.534.1394"
}
]
}
]
}
But when I call in my iOS response this happens
{
"code": 200,
"message": "Listing found.",
"data": [
{
"_id": "67c5596998c649dfa0d45a48",
"tableData": [
{
"Email": "[email protected]",
"Phone": "309.534.1394",
"Name": "Mose Boyle"
}
]
}
]
}
Position randomly changes.
Keys are dynamic so I can't create the model for that.
Share Improve this question edited Mar 25 at 10:28 Larme 26.1k6 gold badges58 silver badges87 bronze badges Recognized by Mobile Development Collective asked Mar 25 at 10:09 Keval dattaniKeval dattani 11 bronze badge 3 |1 Answer
Reset to default 0Because it is... what it is, according to the JSON definition:
An object is an unordered set of name/value pairs. An object begins with {left brace and ends with }right brace. Each name is followed by :colon and the name/value pairs are separated by ,comma.
So, its order doesn't matter, you can conform to Codable
to parse it, like this:
struct TableData: Codable {
let id: String
let tableData: [Person]
enum CodingKeys: String, CodingKey {
case id = "_id"
case tableData
}
}
struct Person: Codable {
let name: String
let email: String
let phone: String
enum CodingKeys: String, CodingKey {
case name = "Name"
case email = "Email"
case phone = "Phone"
}
}
本文标签: jsonResponse key value position changing in iOS swiftStack Overflow
版权声明:本文标题:json - Response key value position changing in iOS swift - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744204561a2595124.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
let dict 1 = ["A": 1, "B": 2]
is the same aslet dict2 = ["B": 2, "A": 1]
or are they different? Dictionary is a basic concept that you must master at the beginning of your coding journey. – Larme Commented Mar 25 at 10:29