Ответ должен быть фиксированной структуры. так что вы декодируете в соответствии с этим.

я хочу расшифровать мой JSON, происходит нечто странное.

Вот структуры

struct chatMessages : Codable {
    var message: [chatMessage]
}

struct chatMessage : Codable {
    var user: String
    var message: String
    var status: String
    var latitude: Double
    var longitude: Double

    init(from decoder: Decoder) throws {
        let values = try decoder.container(keyedBy: CodingKeys.self)
        user = try values.decode(String.self, forKey: .user)
        message = try values.decode(String.self, forKey: .message)
        status = try values.decode(String.self, forKey: .status)
        latitude = try values.decodeIfPresent(Double.self, forKey: .latitude) ?? 0.0
        longitude = try values.decodeIfPresent(Double.self, forKey: .longitude) ?? 0.0
    }
}

И здесь функция

   func loadChats() {
        print("Try to load chats...")
        do {
        let jsonData = W.getDataAsData(chatURL)
            print(jsonData)
            print(String.init(data: jsonData, encoding: .utf8)!)
            print("-----------")
            let jsonDecoder = JSONDecoder()
            let chatMessage1 = try jsonDecoder.decode(chatMessage.self, from: jsonData)
            print(chatMessage1)
        }
        catch {
            print("Something went wrong")
            print("\(error)")
        }
    }

если возвращенный JSON{"user":"test","message":"Hello welcome","status":"admin","latitude":0,"longitude":0}.

его возвращениеchatMessage(user: "test", message: "Hello welcome", status: "admin", latitude: 0.0, longitude: 0.0)

но если есть еще сообщения, например[{"user":"user1","message":"Hello welcome","status":"admin","latitude":0,"longitude":0},{"user":"user2","message":"Hello welcome","status":"admin","latitude":0,"longitude":0}]&nbsp;Я не могу заставить его работать. Его возвращениеtypeMismatch(Swift.Dictionary<Swift.String, Any>, Swift.DecodingError.Context(codingPath: [], debugDescription: "Expected to decode Dictionary<String, Any> but found an array instead.", underlyingError: nil))

Я пробовал сchatMessages.self&nbsp;но это не так, как ожидалось. Что я делаю неправильно?

Заранее спасибо.