//
//  Dictionary+Extension.swift
//  galaxy
//
//  Created by davidhuangA on 2023/12/28.
//  Copyright © 2023 www.davidhuang.com. All rights reserved.
//

import Foundation
extension Dictionary {
    /// 字典转Json字符串
    func yh_toJSONString() -> String? {
        if (!JSONSerialization.isValidJSONObject(self)) {
            print("无法解析出JSONString")
            return nil
        }
        do {
            let data = try JSONSerialization.data(withJSONObject: self, options: [])
            let json = String(data: data, encoding: String.Encoding.utf8)
            return json
        } catch {
            return nil
        }
    }
}
