[{\“目的地\”:\“ Bhainsa \”,\“ travelMode \”:\“航班\”,\“公司\”:\“是\”,\“来源\”:\“阿迪拉巴德\“}]
//这是我的代码
let data1 = try! JSONSerialization.data(withJSONObject: arrat2, options: [])
let jsonString = String(data: data1, encoding: .utf8)!
答案 0 :(得分:1)
您可能需要
let str = """
[{\"destination\":\"Bhainsa\",\"travelMode\":\"Flight\",\"company\":\"Yes\",\"origin\":\"Adilabad\"}]
"""
let res = try! JSONSerialization.jsonObject(with: str.data(using:.utf8)!, options: []) as! [[String:Any]]
let resStr = "\(res)"
print(resStr) // [["origin": Adilabad, "travelMode": Flight, "company": Yes, "destination": Bhainsa]]
let ggg = str.replacingOccurrences(of: "\\", with: "")
print(ggg) // [{"destination":"Bhainsa","travelMode":"Flight","company":"Yes","origin":"Adilabad"}]