Convert a simple string to JSON String in swift

前端 未结 2 765
我在风中等你
我在风中等你 2021-02-08 13:40

I know there is a question with same title here. But in that question, he is trying to convert a dictionary into JSON. But I have a simple sting like this: \"garden\"

A

2条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-02-08 13:43

    Swift 3 Version:

        let location = ["location"]
        if let json = try? JSONSerialization.data(withJSONObject: location, options: []) {
            if let content = String(data: json, encoding: .utf8) {
                print(content)
            }
        }
    

提交回复
热议问题