swifty-json

How to check if key exists in swiftyJSON when json contain array with no keys

坚强是说给别人听的谎言 提交于 2019-12-21 07:36:09
问题 I know about swiftyJSON method exists() but it does not seem to work always as they say. How can I get proper result in this case below? I cannot change JSON structure because I am getting this through client's API. var json: JSON = ["response": ["value1","value2"]] if json["response"]["someKey"].exists(){ print("response someKey exists") } Output: response someKey exists That shouldn't be printed because someKey does not exist. But sometimes that key comes from client's API, and i need to

Is SwiftyJson capable of converting a custom swift class to a json string?

雨燕双飞 提交于 2019-12-21 04:21:06
问题 Given below is my custom swift class. My Question is how to convert an object of this class to a json string using SwiftyJson? class Equipment{ var UniqueItemId:String? = "" var ItemNo:String? = "" var EquipmentType:String? = "" var EquipmentDescription:String? = "" var Length:String? = "" var Wll:String? = "" var EquipmentLocation:String? = "" var EquipmentManufacture:String? = "" var SerialNo:String? = "" var Condition:String? = "" var Remarks:String? = "" var InspectionDate:String? = ""

Postman request to Alamofire request

杀马特。学长 韩版系。学妹 提交于 2019-12-20 07:35:53
问题 I'm having no issues when I make the post request with POSTMAN but when I use alamofire I have issues. The post still goes through on the alamofire request but the data is not received the same way. What does an alamofire request look like that's the exact same as the following postman... 回答1: Swift 2.x : typealias apiSuccess = (result: NSDictionary?) -> Void typealias apiProgress = (result: NSDictionary?) -> Void // when you want to download or upload using Alamofire.. typealias apiFailure =

Swift Function to parse JSON and return a array of dictionaries

风流意气都作罢 提交于 2019-12-18 09:45:58
问题 I tried to write a function to parse a JSON. The return-value of the function is an array of dictionaries. Unfortunately, I have the problem that the assignment result = data as! [[String:AnyObject]] does not work. the print(data) returns my JSON wonderful back but the print(result) only gives me a empty array back. surprising it is that the method print(result) runs first and then the method print(data) run. The code i have try: import Foundation import Alamofire import SwiftyJSON func

URL Encode Alamofire GET params with SwiftyJSON

对着背影说爱祢 提交于 2019-12-18 05:18:16
问题 I am trying to have Alamofire send the following parameter in a GET request but it's sending gibberish: filters={"$and":[{"name":{"$bw":"duke"},"country":"gb"}]} //www.example.com/example?filters={"$and":[{"name":{"$bw":"duke"},"country":"gb"}]} //Obviously URL encoded This is my code: let jsonObject = ["$and":[["name":["$bw":string], "country":"gb"]]] let json = JSON(jsonObject) print(json) outputs { "$and" : [ { "name" : { "$bw" : "duke" }, "country" : "gb" } ] } This is my params request:

Module compiled with swift 3.0 cannot be imported in Swift 3.0.1

对着背影说爱祢 提交于 2019-12-17 08:17:08
问题 I upgraded Xcode to 8.1 GM and am now getting the below error for SwiftyJSON. Other imported frameworks seem to work. Is there a way to force this to work in Swift 3 until SwiftyJSON upgrades their framework? I used Carthage to import/update frameworks. I also tried changing Use Legacy Swift language version On and Off to no avail. Module compiled with Swift 3.0 cannot be imported in Swift 3.0.1: Modules/SwiftyJSON.swiftmodule/arm64.swiftmodule 回答1: SwiftyJson is being downloaded precompiled

Creating JSON Array in Swift

自作多情 提交于 2019-12-14 03:55:49
问题 My backend is expecting the following JSON body: [ { "number":"561310" }, { "number":"132333" }, { "number":"561310" } ] It works very nicely in Postman when I enter it like so: How can I create a similar JSON using Swift? Right now I've an array of phone numbers with the type String. let phonenumbers = [String]() for phonenumber in phonenumbers { print(phonenumber) } This will print: 561310 132333 561310 After making this JSON I want to use it as a parameter for AlamoFire. 回答1: let

dyld: Library not loaded: @rpath/SwiftyJSON.framework/SwiftyJSON

梦想与她 提交于 2019-12-14 00:20:35
问题 This is a sequel to question : dyld: Library not loaded: @rpath/SwiftyJSON.framework/SwiftyJSON After rebuilding the project from scratch (new project, new podfile, new files but in each file copy-paste the source code from the original project) the app compiles now and runs perfectly on every simulator! No Errors. However running on an iPhone 4S or on a iPad 2 I get the same error BUT different reason : dyld: Library not loaded: @rpath/SwiftyJSON.framework/SwiftyJSON Referenced from:

save and retrieve array to user default using swift

早过忘川 提交于 2019-12-13 10:08:14
问题 I want to save array from json to user default, I'll get the array when I print it. When I retrieve it in different view controller I only get the last array. So how to retrieve all data user default in different view controller. This is how I save my code in user default first view controller let kode_pelaksanaan = item["kode_pelaksanaan"].string UserDefaults.standard.set(kode_pelaksanaan, forKey: "kode_pelaksanaan") output: kode_pelaksanaan : ELR2018120005 kode_pelaksanaan : ELR2018120004

NSObject does not have a member named Key error

夙愿已清 提交于 2019-12-13 07:15:25
问题 I need to construct a JSON object in the format shown below. { "DeviceCredentials": { "UniqueId": "sample string 1" }, "Handovers": [ { "Occasions": [ { "Id": 1 }, { "Id": 1 } ] } ] } There is a issue though with the Occasions array though. The number of Occasion objects vary. Sometimes there can be only one Occasion, sometimes multiple. Since this is dynamic I wrote the below method to create this array. func getOccasionArray(handover: Handover) -> JSON { var occArray = [[String: NSNumber]](