草庐IT

zlib_decode

全部标签

ios - 使用 Decodable 链接多个 JSON 请求 - Swift 5

我的“url”对象有一个链接,该链接捕获用户在搜索栏中键入的内容以完成链接,然后开始JSON过程。在JSON完成解析后,第一个链接以另一个链接响应。在我的ifletvalidLink=result.link中,您会看到我将链接信息存储到一个数组中。现在我不确定我是否应该在我的ifletvalidLink=result中开始另一个JSON响应,或者我是否应该像我在下面的代码中尝试做的那样创建一个新函数并基本上复制和在下面粘贴相同的JSON信息以重新解析它。第二个链接出现解析错误。最有效和正确的方法是什么?我真的被困在这里了。我尝试创建另一个函数,该函数使用来自第一个JSON解析的信息使用

json - swift 可编码 : Decode different array of items with same root objects

我目前正在尝试解码如下所示的JSON:{"result":{"success":true,"items":[{"timeEntryID":"1","start":"1519558200","end":"1519563600","customerName":"Test-Customer","projectName":"Test-Project","description":"Entry1",},{"timeEntryID":"2","start":"1519558200","end":"1519563600","customerName":"Test-Customer","project

ios - 如何在 Swift 4 中将 Encodable 或 Decodable 作为参数传递?

我正在学习JSONParsing。我按照教程进行操作,得到的是:guardleturl=URL(string:"http://localhost/test-api/public/api/register")else{return}varrequest=URLRequest(url:url)request.httpMethod="POST"letnewUser=User.init(name:self.collectionTF[0].text,email:self.collectionTF[1].text,password:self.collectionTF[2].text)do{letj

ios - 如何在 Swift 中使用 Decodable?

我在我的项目中使用免费日期API。我正在使用Decodable来解析JSON数据。我在这里创建了我的结构:-structjsonStruct:Decodable{varmessage:Bool?vardata:[dateData]}structdateData:Decodable{varquarter:Int?varday:String?varmonth:String?}这是我使用解码器的代码:-letjsonUrlString="https://api.lrs.org/random-date-generator?lim_quarters=40&source=api-docs"guar

swift 3 : How to catch error if NSCoder decodeX function decodes wrong value type?

Swift3改变了NSCoder的工作方式。正如其他SO问题所提到的,要解码Int或Bool等值类型,您必须使用特定函数。例如,decodeInteger用于解码Int值,如下所示:letvalue=decodeInteger(forKeykey:TestKey)但是,如果decodeInteger返回的值是String或Bool或Int以外的值怎么办?或者如果TestKey实际上映射为空,因为它包含错误的key数据怎么办?如何优雅地捕获这些错误? 最佳答案 在非整数键上使用decodeInteger会引发异常。遗憾的是,这是一个S

json - 如何使用 Decodable 协议(protocol)将此 JSON 转换为 Swift 结构?

注意:这个问题我已经看过了->HowdoIusecustomkeyswithSwift4'sDecodableprotocol?但它没有解释如何编码/解码枚举这是我想要的结构:structMyStruct:Decodable{letcount:PostType}enumPostType:Decodable{casefast(value:Int,value2:Int)caseslow(string:String,string2:String)}现在我知道我希望我的结构看起来如何,问题是:我不知道init函数在PostType枚举中应该是什么样子。我使用下面的代码来帮助我快速构建JSON。

swift - 字符串字典 :Any does not conform to protocol 'Decodable'

这个问题在这里已经有了答案:Fatalerror:DictionarydoesnotconformtoDecodablebecauseAnydoesnotconformtoDecodable(2个答案)关闭4年前。我正在尝试实现一个Decodable来解析json请求,但json请求在对象内部有一个字典。这是我的代码:structmyStruct:Decodable{letcontent:[String:Any]}enumCodingKeys:String,CodingKey{casecontent="content"}但是我收到了这个错误:类型“MyClass.myStruct”不符

ios - 如何在 init 中捕获错误(来自解码器 :Decoder) from a Codable struct?

letjsonString="""{"name":1,"gender":"male",}"""structPerson:Codable{varname:Stringvargender:Stringpublicinit(fromdecoder:Decoder)throws{do{letcontainer=trydecoder.container(keyedBy:CodingKeys.self)name=trycontainer.decode(String.self,forKey:.name)gender=trycontainer.decode(String.self,forKey:.ge

json - 使用 Swift 的 Decodable 协议(protocol)解析 CoinMarketCap API

我已阅读HowtodecodeanestedJSONstructwithSwiftDecodableprotocol?它没有解决我将字符串文字数字值用作根字典的特定用例。还有HowtodecodeanestedJSONstructwithSwiftDecodableprotocol?ImanouPetit的回答。Can'tdecodeJSONdatafromAPILeoDabus的回答。货币本身就是字典,由data字典中的文字字符串数字表示,所以这让我很反感。我正在寻找使用枚举的最多的Swifty4模型,在其中可以很容易地看到哪些容器对应于哪些词典。附注DavidBerry给出了一个很

swift - 使用 Decodable 将空 JSON 字符串值解码为 nil

假设我有这样一个结构:structResult:Decodable{letanimal:Animal?}像这样的枚举:enumAnimal:String,Decodable{casecat="cat"casedog="dog"}但是返回的JSON是这样的:{"animal":""}如果我尝试使用JSONDecoder将其解码为Result结构,我会得到CannotinitializeAnimalfrominvalidStringvalue作为一个错误信息。我如何正确地将此JSON结果解码为动物属性为nil的Result? 最佳答案