swifty-json

Create JSON Object from Class in Swift

微笑、不失礼 提交于 2019-12-04 11:39:55
I'm pretty new to iOS development and Swift (so please bear with me). I have a class object defined like this: class LocationPoint { var x: Double var y: Double var orientation: Double init(x: Double, y: Double, orientation: Double) { self.x = x self.y = y self.orientation = orientation } } In my delegate, I create an instance of the class and append it to an array (declared outside the delegate): var pt = LocationPoint(x: position.x, y: position.y, orientation: position.orientation) self.LocationPoints.append(pt) So far so good. I can show the array values in a textview object in my

how to parsing Json with SwiftyJson from woocommerce api?

蓝咒 提交于 2019-12-04 06:26:58
问题 I want to parse JSON using alamofire and swiftyjson I try get JSON(value) like this let headers: HTTPHeaders = [ "Authorization": "Basic Y2tfZTA1ZGNmMDkwNTNmODEyMGQwYTMyOGI4YzJkY2QzOTY5MmE5ZDAyNzpjc18zYzZiYWY2NTM0NDhkNDM4ZDM1ZDNmNDY5Nzg5ZGM2Y2VhZGRiZjNl", "Accept": "application/json" ] Alamofire.request("https://woo.demoapp.xyz/wp-json/wc/v2/products?category=15", headers: headers).responseJSON { response in debugPrint(response) if let json = response.result.value { print("JSON: \(json)") } }

SwiftyJSON - 'inout JSON' is not convertible to 'JSON'

走远了吗. 提交于 2019-12-04 05:42:11
问题 I'm facing a JSON parsing issue I've no idea how to fix. I need this part of the JSON data "columns": { "created_at": "DESC", "id": "DESC" } to be stored in a [String: String]? optional dictionary. So, this is the code I'm using: self.columns = json["columns"].dictionary?.map { (key, value) -> (String, String) in return (key, value.stringValue) } This however produces a compiler error: 'inout JSON' is not convertible to 'JSON' I should probably add that this is part of a pretty large piece of

How Can I Parse Json In Json With SwiftyJSON?

杀马特。学长 韩版系。学妹 提交于 2019-12-04 05:11:00
问题 I am returning the following JSON from an API. In my database, I store a list in JSON already. Thus, it gives us a string of JSON inside JSON. How can I access these as objects in Swift? More to the point: How can I parse JSON inside of JSON? { "checklists": [ { "id": 1, "account_id": 15, "user_id": 15, "object_id": 21, "checklist": "[{\"title\":\"Test\",\"summary\":\"Test 12\"},{\"title\":\"Test 2 \",\"summary\":\"Test 123\"}]", "title": "High Altitude Operations", "type": "other",

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

被刻印的时光 ゝ 提交于 2019-12-04 03:36:57
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: /private/var/mobile/Containers/Bundle/Application/EFC891F9-C22B-4503-8F11-F30769183439/Demo Mobile.app/Demo

How to create objects from SwiftyJSON

孤者浪人 提交于 2019-12-04 00:42:42
I have a code, that parses JSON's list of questions and I can get every property. How can I iterate through the whole file and for each question create an object ? class ViewController: UIViewController { var hoge: JSON? override func viewDidLoad() { super.viewDidLoad() let number = arc4random_uniform(1000) let url = NSURL(string: "http://www.wirehead.ru/try-en.json?\(number)") var request = NSURLRequest(URL: url!) var data = NSURLConnection.sendSynchronousRequest(request, returningResponse: nil, error: nil) if data != nil { hoge = JSON(data: data!) let level = hoge!["pack1"][0]["level"]

Convert a simple string to JSON String in swift

感情迁移 提交于 2019-12-03 17:15:42
问题 I know there is a question with same title here. But in that question, he is trying to convert a dictionary into JSON. But I have a simple sting like this: "garden" And I have to send it as JSON. I have tried SwiftyJSON but still I am unable to convert this into JSON. Here is my code: func jsonStringFromString(str:NSString)->NSString{ let strData = str.dataUsingEncoding(NSUTF8StringEncoding) let json = JSON(data: strData!) let jsonString = json.string return jsonString! } My code crashes at

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

谁说我不能喝 提交于 2019-12-03 12:31:21
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? = "" var Inspector:String? = "" } For example, like this: var jsonString = JSON(equipmentObject); UPDATE OP is

NSDictionary to json string to json object using SwiftyJSON

老子叫甜甜 提交于 2019-12-03 08:22:18
I have a use case where I have an array of dictionaries and I need them as a json object: var data = [Dictionary<String, String>]() //append items var bytes = NSJSONSerialization.dataWithJSONObject(data, options: NSJSONWritingOptions.allZeros, error: nil) var jsonObj = JSON(NSString(data: bytes!, encoding: NSUTF8StringEncoding)!) println(jsonObj) println(jsonObj[0]) The first print statement gives me [ {"price":"1.20","city":"Foo","_id":"326105","street":"One"}, {"price":"1.20","city":"Bar","_id":"326104","street":"Two"} ] the second null but I would expect it to return the first element in

Convert a simple string to JSON String in swift

笑着哭i 提交于 2019-12-03 06:15:56
I know there is a question with same title here . But in that question, he is trying to convert a dictionary into JSON. But I have a simple sting like this: "garden" And I have to send it as JSON. I have tried SwiftyJSON but still I am unable to convert this into JSON. Here is my code: func jsonStringFromString(str:NSString)->NSString{ let strData = str.dataUsingEncoding(NSUTF8StringEncoding) let json = JSON(data: strData!) let jsonString = json.string return jsonString! } My code crashes at the last line: fatal error: unexpectedly found nil while unwrapping an Optional value Am I doing