swifty-json

Alamofire request coming up nil

穿精又带淫゛_ 提交于 2019-12-24 15:42:49
问题 I'm developing an iOS app which user WebServices and I find Alamofire just perfect for what I'm doing but I'm having a problem; the app asks the user to login which is an Alamofire call and does it just fine. The problem is, it has to create a collection view based on the content of another Alamofire request but is always nil . func getJSON(URLToRequest: String) -> JSON { let comp:String = (prefs.valueForKey("COMPANY") as? String)! let params = ["company":comp] var json:JSON! let request =

How can I use swiftyJSON dictionaryValue as a usable string for a UILabel?

旧时模样 提交于 2019-12-24 15:23:14
问题 I have a makeRequest() method inside a UITableViewController with the following code: func makeRequest() { Alamofire.request(.GET, self.foursquareEndpointURL, parameters: [ //"VENUE_ID" : self.foursquareVenueID, "client_id" : self.foursquareClientID, "client_secret" : self.foursquareClientSecret, "v" : "20140806" ]) .responseJSON(options: nil) { (_, _, data, error) -> Void in if error != nil { println(error?.localizedDescription) } else if let data: AnyObject = data { let jObj = JSON(data) if

SwiftyJSON to read local file

非 Y 不嫁゛ 提交于 2019-12-24 14:10:05
问题 So my app is using a JSON API response to read some data from server. Since the API is not yet ready i want to use a sample JSON file which is stored in my app itself. Since all my code uses SwiftyJSON i want to stick to it for the local file. I am doing the following in my ViewDidLoad method and somehow this end result is a blank array. Do you know what should i change in this code to make it work? //Direct JSON if let path = NSBundle.mainBundle().pathForResource("XXYYXZZfile", ofType: "json

Converting Object to JSON String For POST Request

时光怂恿深爱的人放手 提交于 2019-12-24 12:16:01
问题 I have an object that is an instance of a class similar to this: class MyClass { let aString: String let bString: String var cArray = [AnotherClass]() init etc... } AnotherClass is something like: class AnotherClass { let aInt: Int let bInt: Int var cFloat = Float init etc... } Ok, now i need to pass that object (instance of MyClass) as a POST request string parameter with the following format: { "aString": "1", "bString": "yannis", "cArray": [ { "aInt": 1965887, "bInt": 36513032311523,

Alamofire Post Request with nested JSON parameters

牧云@^-^@ 提交于 2019-12-24 09:42:25
问题 My Alamofire post request looks like this: Alamofire.request("http://...", method: HTTPMethod.post, parameters: parameters, encoding: JSONEncoding.default, headers: nil) .responseJSON(completionHandler: {(response) in ... }) Everything works fine if my parameters are simple: let parameters: Parameters = [ "firstName": "John", "lastName": "Doe" ] I run into problems if my parameters contain a json object. let address: JSON = [ "street": "1234 Fake St", "city": "Seattle", "state": "WA" ] let

How to remove a SwiftyJSON element?

被刻印的时光 ゝ 提交于 2019-12-23 16:04:28
问题 I have a JSON array (say, dataObj ) generated by SwiftyJSON and I try to remove its element like this: let count=dataObj.count for var m=x; m<count; ++m { dataObj[m] = nil // there is no removeAtIndex() somehow } print(dataObj.count) print(dataObj) After execution, dataObj.count remains the same and print shows now dataObj becomes [null, null, null, ... ] What's the way to really remove an element for SwiftyJSON? 回答1: Finally I found the answer to remove an element in JSON (array type)

How to write Unit Test for Alamofire request function?

…衆ロ難τιáo~ 提交于 2019-12-23 15:19:29
问题 I have a project where I'm sending .GET requests to get data from the server and for this I'm using Alamofire & SwiftyJSON. For example: I have file "Links", "Requests" and my ViewController. Links.swift var getAllData: String { return "\(host)api/getalldata" } Requests.swift func getAllData(_ completion:@escaping (_ json: JSON?) -> Void) { Alamofire.request(Links.sharedInstance.getAllData).validate().responseJSON { (response) in do { let json = JSON(data: response.data!) completion(json) } }

Alamofire and SwiftyJSON for Swift 2.0

北战南征 提交于 2019-12-22 13:58:53
问题 I am updating my code for Swift 2.0 for today, however the line var json = JSON(json) gives me the following error Cannot invoke intializer for type 'JSON' with an argument list of type (Result) Do you guys have any idea how should I change my code? @IBAction func changePassword(sender: UIBarButtonItem) { Alamofire.request(.POST, AppDelegate.kbaseUrl + "users/me/password", parameters: ["old_password": self.oldPasswordTextField.text!, "new_password": self.newPasswordTextField.text!, "confirm

Alamofire and SwiftyJSON for Swift 2.0

可紊 提交于 2019-12-22 13:58:12
问题 I am updating my code for Swift 2.0 for today, however the line var json = JSON(json) gives me the following error Cannot invoke intializer for type 'JSON' with an argument list of type (Result) Do you guys have any idea how should I change my code? @IBAction func changePassword(sender: UIBarButtonItem) { Alamofire.request(.POST, AppDelegate.kbaseUrl + "users/me/password", parameters: ["old_password": self.oldPasswordTextField.text!, "new_password": self.newPasswordTextField.text!, "confirm

How to sort JSON coming from Alamofire and return final JSON object (swiftyJSON)

怎甘沉沦 提交于 2019-12-21 22:17:31
问题 I'm having trouble succinctly pulling data from an api, adding the users current location into the object and then sorting the data based on the calculated distance. The stackoverflow questions don't quite answer the problem I'm facing. See here: How to sort posts read from JSON server file in Swift. I'm currently loading api data from Alamofire and rendering that data with a UITableViewController. override func viewDidLoad() { super.viewDidLoad() titleLabel.title = q.capitalizedString