swifty-json

How do I access a nested JSON value using Alamofire and SwiftyJSON?

大城市里の小女人 提交于 2019-12-01 10:49:25
I am trying to access nested JSON results using swiftyJSON and Alamofire. My print value is nill and I believe I am not doing this correctly. What should my parameters be? I am trying to get the quote value located at http://quotes.rest/qod.json func getAPI() { Alamofire.request(.GET, "http://quotes.rest/qod.json", parameters: ["contents": "quotes"]) .responseJSON { response in if let JSON = response.result.value { print(JSON["quote"]) } } } In your JSON quotes is an array so if you want to access quote of the first object you should do it by accessing first object: func getAPI() { Alamofire

How do I access a nested JSON value using Alamofire and SwiftyJSON?

半城伤御伤魂 提交于 2019-12-01 09:38:58
问题 I am trying to access nested JSON results using swiftyJSON and Alamofire. My print value is nill and I believe I am not doing this correctly. What should my parameters be? I am trying to get the quote value located at http://quotes.rest/qod.json func getAPI() { Alamofire.request(.GET, "http://quotes.rest/qod.json", parameters: ["contents": "quotes"]) .responseJSON { response in if let JSON = response.result.value { print(JSON["quote"]) } } } 回答1: In your JSON quotes is an array so if you want

How to parse the json data using swiftJson along with Alamofire

那年仲夏 提交于 2019-12-01 07:38:10
问题 my Json data sample. this is only a sample of data .Likewise so much data available like number of subcategory is 22. number of items are different according to subcategory.Also number of rows are 15 in which the first name is Pizza. [ { "id": "244", "name": "PIZZAS", "image": "", "coupon": "1", "icon": "", "order": "1", "aname": "", "options": "2", "subcategory": [ { "id": "515", "name": "MARGARITA", "description": "Cheese and Tomato", "image": "", "icon": "", "coupon": "1", "order": "1",

Get JSON result with GET request and parameters with Alamofire

泄露秘密 提交于 2019-12-01 06:29:20
This is my url String with paramaters. http://api.room2shop.com/api/product/GetProducts?categoryId=22&filter=2&pageNumber=1 through which I am getting my JSON data. I have AFWrapper.swift file in which I have defined function for GETrequest. import UIKit import Alamofire import SwiftyJSON class AFWrapper: NSObject { class func requestGETURL(strURL: String, params : [String : AnyObject]?, success:(JSON) -> Void, failure:(NSError) -> Void) { Alamofire.request(.GET, strURL, parameters: params, encoding: ParameterEncoding.JSON).responseJSON { (responseObject) -> Void in print(responseObject) if

Get JSON result with GET request and parameters with Alamofire

末鹿安然 提交于 2019-12-01 05:34:15
问题 This is my url String with paramaters. http://api.room2shop.com/api/product/GetProducts?categoryId=22&filter=2&pageNumber=1 through which I am getting my JSON data. I have AFWrapper.swift file in which I have defined function for GETrequest. import UIKit import Alamofire import SwiftyJSON class AFWrapper: NSObject { class func requestGETURL(strURL: String, params : [String : AnyObject]?, success:(JSON) -> Void, failure:(NSError) -> Void) { Alamofire.request(.GET, strURL, parameters: params,

How to loop through JSON with SwiftyJSON?

橙三吉。 提交于 2019-11-30 06:21:45
问题 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"]

SwiftyJSON object back to string

与世无争的帅哥 提交于 2019-11-30 05:42:53
I'm using the SwiftyJSON library to parse JSON into swift objects. I can create the JSON object and read and write to it // Create json object to represent library var libraryObject = JSON(["name":"mylibrary","tasks":["Task1","Task2","Task3"]]) // Get println(libraryObject["name"]) println(libraryObject["tasks"][0]) // Set println("Setting first task to 'New Task'") libraryObject["tasks"][0] = "New Task" // Get println(libraryObject["tasks"][0]) // Convert object to JSON and print println(libraryObject) All of this works as expected. I just want to convert the libraryObject back to a string in

URL Encode Alamofire GET params with SwiftyJSON

一世执手 提交于 2019-11-29 08:45:28
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: let params = ["filters" : json.rawValue, "limit":"1", "KEY":"my_key"] This is what AlamoFire is sending

Using SwiftyJSON with Swift3

时光毁灭记忆、已成空白 提交于 2019-11-29 07:05:37
问题 How do I use SwiftyJSON with Swift3? I've installed the pod. pod 'SwiftyJSON', :git => 'https://github.com/SwiftyJSON/SwiftyJSON.git', :branch => 'swift3' But it throws a lot of errors using Xcode 8 GM. Can someone help me install it properly? 回答1: SwiftyJSON now supports Swift 3. pod 'SwiftyJSON', '3.0.0' 回答2: Update: as Marcus notes, SwiftyJSON now supports Swift 3. In order to get bug fixes, I recommend not pinning yourself to 3.0.0, but rather: pod 'SwiftyJSON', '>= 3.0.0' …or if you don

SwiftyJSON object back to string

混江龙づ霸主 提交于 2019-11-29 06:07:14
问题 I'm using the SwiftyJSON library to parse JSON into swift objects. I can create the JSON object and read and write to it // Create json object to represent library var libraryObject = JSON(["name":"mylibrary","tasks":["Task1","Task2","Task3"]]) // Get println(libraryObject["name"]) println(libraryObject["tasks"][0]) // Set println("Setting first task to 'New Task'") libraryObject["tasks"][0] = "New Task" // Get println(libraryObject["tasks"][0]) // Convert object to JSON and print println