ios cocoapods pod install 卡住怎么办? (2) 问题: pod install 发现某个 pod 一直安装失败 错误提示: [crayon-673f122a1… Read More
ios UIScrollView 里边放一个 UIStackView 该怎么设置 AutoLayout 约束 问题 UIScrollView 里边放一个 UIStackView 该怎么设置 AutoLayout 约束 &… Read More
swift toJson 问题: 解决: import Foundation func toJson(obj : Any) -> String?{ do { let aa = toObj(obj:obj) let jsonData = try JSONSerialization.data(withJSONObject: aa, options: []) let jsonString = String.init(data: jsonData, encoding: .utf8) return jsonString } catch { print(error) return nil } } func toObj(obj : Any) -> Any{ if let a = obj as? [Any] { var a2 = [Any]() for e in a { let d = toObj(obj: e) a2.append(d) } return a2 }else if obj is Int || obj is String || obj is Bool || obj is Float || obj is Double || obj is NSNull { return obj } else { let dic = toDictionary(obj: obj); if dic.count > 0 { return dic }else {////optional none return obj } } } func toDictionary(obj : Any) -> [String: Any] { var dictionary = [String: Any]() let otherSelf = Mirror(reflecting: obj) for child in otherSelf.children { guard let key = child.label else { continue } let v = child.value dictionary[key] = toObj(obj:v) } return dictionary } extension Dictionary { func floatValue(_ name:Dictionary.Key) ->Float?{ var ret : Float? = nil if let n = self[name] as? NSNumber { ret = n.floatValue }else if let f = self[name] as? Float { ret = f } return ret } } 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 import Foundation func toJson(obj : Any) -> String?{ do { let aa = toObj(obj:obj) let jsonData = try JSONSerialization.data(withJSONObject: aa, options: []) let jsonString = String.init(data: jsonData, encoding: .utf8) return jsonString } catch { print(error) return nil }}func toObj(obj : Any) -> Any{ if let a = obj as? [Any] { var a2 = [Any]() for e in a { let d = toObj(obj: e) a2.append(d) } return a2 }else if obj is Int || obj is String || obj is Bool || obj is Float || obj is Double || obj is NSNull { return obj } else { let dic = toDictionary(obj: obj); if dic.count > 0 { return dic }else {////optional none return obj } }} func toDictionary(obj : Any) -> [String: Any] { var dictionary = [String: Any]() let otherSelf = Mirror(reflecting: obj) for child in otherSelf.children { guard let key = child.label else { continue } let v = child.value dictionary[key] = toObj(obj:v) } return dictionary} extension Dictionary { func floatValue(_ name:Dictionary.Key) ->Float?{ var ret : Float? = nil if let n = self[name] as? NSNumber { ret = n.floatValue }else if let f = self[name] as? Float { ret = f } return ret }} … Read More