Created
November 18, 2020 03:20
-
-
Save Andy0570/5669b5195b2c5b2da13cbc6be3daa01b to your computer and use it in GitHub Desktop.
JSON 字符串解析
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
extension String { | |
init?(json: Any) { | |
guard let data = Data(json: json) else { return nil } | |
self.init(decoding: data, as: UTF8.self) | |
} | |
func jsonToDictionary() -> [String: Any]? { | |
self.data(using: .utf8)?.jsonToDictionary() | |
} | |
func jsonToArray() -> [Any]? { | |
self.data(using: .utf8)?.jsonToArray() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage: