cost 134 ms
JSON解析Swift。當value不為nil時,我可以解析JSON數據。 如果值為 nil,我將收到一個空數組而不是 nil

[英]JSON parsing in Swift. When value is not nil, I can parse the JSON data. If value is nil, I receive an empty array instead of nil

所以,讓我用一個例子詳細說明一下: 假設我想獲取有關人員的數據。 每個人都有 3 個 collections:朋友、家人和工作。 Friends 集合包含:Person 對象(描述每個朋友:name age aso) Family 集合包含:Person 對象(描述每個家庭成員:name ag ...

在 Swift 中使用 Codable 將 JSON 解析為對象數組而不是字典

[英]Parse JSON as array of objects instead of dictionary using Codable in Swift

我從 API 收到以下 JSON 我創建了 model 來解析這個 JSON 並且它有效。 但我需要獲取對象數組而不是字典。 因為我需要以正確的順序獲取值。 我想要這樣的東西: 而且我不明白我應該在我的代碼中更改什么才能使這個 model 工作。 因為現在我得到錯誤“預期解碼數組但找到了字典。” 有 ...

swift解析時如何打印錯誤信息

[英]How to print error message while parsing in swift

這是 json 錯誤結構: 這是成功響應結構: 這里無法在我的代碼中打印錯誤 > 消息代碼:這里能夠在case.success(_)打印語句中打印 json 響應結果或錯誤字典,但是如何只打印error > meaning 如何在下面的代碼中打印錯誤的"Parse error" ,請指導 ...

如何初始化 Codable ObservedObject

[英]How to Initialize Codable ObservedObject

在 SwiftUI 中,我試圖創建一個符合 Codable 的Codable (這樣我可以將它保存在@AppStorage中),並且具有@Published屬性,因此它可以作為EnvironmentObject傳遞。 本教程給了我以下示例: 我想知道 go 如何將String傳遞給 class ...

如何用generics和inheritance解析一個output?

[英]How to use generics and inheritance to parse an output?

我正在為啟用分頁的 NestJs 中的后端編程 a.network 調用。 服務的output結構如下: Meta 和 Links 屬性相當直接,因此沒有問題。 我遇到的問題是項目列表。 里面的objects數據結構可以不同,可以有News, Posts, Events。 所有這些對象都有一些共 ...

如何制作列表並跟蹤 Codable 結構中項目的 position?

[英]How make a list and track the position of item in a Codable Struct?

我有這個結構: 我需要跟蹤項目的 position。 在另一個視圖和結構中,我使用了 firstIndex(of: item) 但是 Xcode 給我一個錯誤,因為這個結構是 CODABLE,另一個結構是 EQUATABLE。 我能做什么? 我需要發送一個帶有產品索引的事件。 ...

Swift Codable:在解碼的 Codable 中包含字典鍵作為屬性 object

[英]Swift Codable: Include dictionary key as property in decoded Codable object

我有一個 JSON object 這樣的: 我將這些中的每一個解碼為標記為Codable的Color object 。 我想將 object 的密鑰作為 object 本身的屬性包含在內,這樣我就可以區分密鑰以提供補充信息,例如擁有一個 function 可以提供與 object 配對的顏色(例如 ...

JSON 在 Swift 中編碼

[英]JSON to Codable in Swift

我很掙扎,因為我不知道如何使用這個 JSON,因為在 JSON 的“天氣”部分,它接收 [0] 作為鍵值,我不知道如何聲明它{ "coord": { "lon": -35.7353, "lat": -9.6658 }, "weather": [ { " ...

使協議在擴展中可編碼

[英]Conforming a protocol to codable in extension

關於這個主題有很多問題,但我還沒有弄清楚為什么我的解決方案還行不通。 我有一些協議 從技術上講,這現在有一個默認實現,可以使整個協議完美解碼。 而且編譯器根本不會抱怨這個。 所以現在在一個結構中,如果我有 然后我收到錯誤Protocol 'Foo' as a type cannot conform ...

在 Swift 中發布解碼異步/等待響應

[英]Issue decoding Async/Await response in Swift

我正在嘗試向生產提交訂單,但一直出現解碼錯誤,我不知道哪里出了問題。 這是完整的錯誤: 錯誤解碼 keyNotFound(CodingKeys(stringValue: "id", intValue: nil), Swift.DecodingError.Context(codingPath: [], ...

如何快速解碼結構

[英]How to decode struct in swift

我有來自服務器的 JsonResponse 這是我的模型結構 我收到找不到 codingKey ("articles") 的錯誤消息,這是完整的錯誤消息: keyNotFound(CodingKeys(stringValue: "articles", intValue: nil), Swift.D ...

從具有所有 CodingKey 和值的 Codable 結構創建字典

[英]Create a dictionary from a Codable struct with all CodingKeys and values

是否可以將CodingKeys struct中屬性的存儲值與所述屬性的Codable相關聯,並在不手動配置每個結構的情況下返回它們? 我正在努力實現以下目標: 使用Mirror()並沒有太大幫助,因為它返回一個標簽,該標簽是作為String的屬性名稱,但我需要 CodingKey。 並且CaseIt ...

Swift 當設備未使用 24 小時格式時,使用自定義 dateDecodingStrategy 的自定義 JSONDecoder 可編碼失敗

[英]Swift Codable with Custom JSONDecoder with Custom dateDecodingStrategy failing when Device is not using 24 hours format

我從服務器獲取以下格式的日期 我正在使用 Codable 將 json 解析為對象。 我正在使用如下所示的自定義解碼器internal func getDecoder() -> JSONDecoder { let decoder = JSONDecoder() let date ...

如何修復此 Swift“解碼找不到密鑰 CodingKeys”錯誤?

[英]How do I fix this Swift "decoding could not find key CodingKeys" error?

**我有這個 JSON:** **我需要解碼。 目前我的 STRUT 看起來像這樣:** 但我收到錯誤: 在 JSON 中找不到鍵 CodingKeys(stringValue:“eaRevenue”,intValue:nil):沒有與鍵 CodingKeys(stringValue:“eaR ...


 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM