swifty-json

How to loop through JSON with SwiftyJSON?

北战南征 提交于 2019-11-28 17:13:32
I have a json that I could parse with SwiftyJSON : if let title = json["items"][2]["title"].string { println("title : \(title)") } Works perfectly. But I couldn't loop through it. I tried two methods, the first one is // TUTO : //If json is .Dictionary for (key: String, subJson: JSON) in json { ... } // WHAT I DID : for (key: "title", subJson: json["items"]) in json { ... } XCode didn't accept the for loop declaration. The second method : // TUTO : if let appArray = json["feed"]["entry"].arrayValue { ... } // WHAT I DID : if let tab = json["items"].arrayValue { ... } XCode didn't accept the if

error after updating the Xcode to 7.0

不打扰是莪最后的温柔 提交于 2019-11-28 10:36:22
问题 I'm developing an iOS application in Swift. When I updated the Xcode to 7.0, I'm getting error in swiftyJSON. static func fromObject(object: AnyObject) -> JSONValue? { switch object { case let value as NSString: return JSONValue.JSONString(value as String) case let value as NSNumber: return JSONValue.JSONNumber(value) case let value as NSNull: return JSONValue.JSONNull case let value as NSDictionary: var jsonObject: [String:JSONValue] = [:] for (k:AnyObject, v:AnyObject) in value {// **THIS

Returning a value from a function with Alamofire and SwiftyJson

℡╲_俬逩灬. 提交于 2019-11-28 01:32:48
I have an app that returns a menu of information (basically menus, menu_headers, and items). I'd like to have something like this: EKMenu.getMenu(menu_id: Int) that would return a menu but I think I would need a completion handler in here. I currently have: class func getMenu(menu_id: Int){ //class func getMenu(menu_id: Int, completionHandler:(NSArray -> Void)){ let url="https://www.example.com/arc/v1/api/menus/\(menu_id)/mobile" Alamofire.request(.GET, url).responseJSON() { (_, _, data, _) in println("within menu request") var json=JSON(data!) var menu=EKMenu() menu.name=json["menu"]["name"]

swiftyjson - Call can throw, but it is marked with 'try' and the error is not handled

限于喜欢 提交于 2019-11-27 16:03:13
I am trying to use swiftyjson and I am getting an Error: Call can throw, but it is marked with 'try' and the error is not handled. I have validated that my source JSON is good. I've been searching and cannot find a solution to this problem import Foundation class lenderDetails { func loadLender() { let lenders = "" let url = URL(string: lenders)! let session = URLSession.shared.dataTask(with: url) { (data, response, error) in guard let data = data else { print ("data was nil?") return } let json = JSON(data: data) print(json) } session.resume() } } Thank you for all the help! You should wrap

Returning a value from a function with Alamofire and SwiftyJson

丶灬走出姿态 提交于 2019-11-26 21:58:57
问题 I have an app that returns a menu of information (basically menus, menu_headers, and items). I'd like to have something like this: EKMenu.getMenu(menu_id: Int) that would return a menu but I think I would need a completion handler in here. I currently have: class func getMenu(menu_id: Int){ //class func getMenu(menu_id: Int, completionHandler:(NSArray -> Void)){ let url="https://www.example.com/arc/v1/api/menus/\(menu_id)/mobile" Alamofire.request(.GET, url).responseJSON() { (_, _, data, _)

swiftyjson - Call can throw, but it is marked with 'try' and the error is not handled

房东的猫 提交于 2019-11-26 17:23:27
问题 I am trying to use swiftyjson and I am getting an Error: Call can throw, but it is marked with 'try' and the error is not handled. I have validated that my source JSON is good. I've been searching and cannot find a solution to this problem import Foundation class lenderDetails { func loadLender() { let lenders = "" let url = URL(string: lenders)! let session = URLSession.shared.dataTask(with: url) { (data, response, error) in guard let data = data else { print ("data was nil?") return } let

How to post nested json by SwiftyJson and Alamofire?

隐身守侯 提交于 2019-11-26 10:00:08
问题 How to post nested json like below as body of method by SwiftyJson and Alamofire?(Swift 3) { \"a\":{ \"a1\": \"v1\", \"a2\": \"v2\" }, \"b\":\"bv\" } I check lots of post Json post nested objects in swift using alamofire , How do I access a nested JSON value using Alamofire and SwiftyJSON? , Alamofire JSON Serialization of Objects and Collections and ... but none of them helped for this situation. 回答1: try this func test() { var exampleParameters : [String : Any] = ["b" : "bv"]