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"
}
}
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