Converting NSString to NSDictionary / JSON

前端 未结 5 1590
时光说笑
时光说笑 2020-12-02 07:05

I have the following data saved as an NSString :

 {
    Key = ID;
    Value =         {
        Content = 268;
        Type = Text;
    };
},
          


        
5条回答
  •  萌比男神i
    2020-12-02 07:40

    Swift 3:

    if let jsonString = styleDictionary as? String {
        let objectData = jsonString.data(using: String.Encoding.utf8)
        do {
            let json = try JSONSerialization.jsonObject(with: objectData!, options: JSONSerialization.ReadingOptions.mutableContainers) 
            print(String(describing: json)) 
    
        } catch {
            // Handle error
            print(error)
        }
    }
    

提交回复
热议问题