I'm working on parsing a JSON file into a dictionary:
// JSON Payload File
{
"orderPlaced": "done",
"prep": "pending",
"shipped" : "pending"
}
Here is my code to make a dictionary from that file:
if let path = Bundle.main.path(forResource: "JSONPayload", ofType: "json") {
do {
// Data from JSON file path
let data = try Data(contentsOf: URL(fileURLWithPath: path), options: [])
// JSON dicrtionary being made
let json = try JSONSerialization.jsonObject(with: data) as! [String: Any]
print(json)
} catch let jsonErr {
print("err", jsonErr)
}
Expected output: ["orderPlaced": done, "prep": pending, "shipped": pending]
The actual output is: ["shipped": pending, "orderPlaced": done, "prep": pending]
Is there a way I can re-order my dictionary or have it ordered from the start. I'm assuming the latter request might not be doable since dictionaires from my understanding are un-ordered. Maybe the only thing I can do is re-order after the dictionary is made, but how would i do that? Do I have to modify my JSON file and the Swift code or just one or ther other?