Problem: How to parse the string that contains the json value? Solution: extension String { var parseJSONString : AnyObject? { let data = self .data(using: String .Encoding.utf8, allowLossyConversion: false ) if let jsonData = data { // Will return an object or nil if JSON decoding fails do { let message = try JSONSerialization.jsonObject(with: jsonData, options:.mutableContainers) if let jsonResult = message as ? NSMutableDictionary { return jsonResult //Will return the json array output ...
We cannot convert string directly to NSNumber. So we will convert string to Int then convert Int to NSNumber. Code: NSNumber (value: Int ( "String" )!)
Comments
Post a Comment