如何将字符串转换为json为简单字符串 - SwiftyJSON

时间:2017-05-18 13:43:16

标签: json swift xcode swift3 swifty-json

我有一个像json这样的字符串:

[
  "http:\/\/kashanmap.ir\/media\/k2\/galleries\/6861\/A.jpg",
  "http:\/\/kashanmap.ir\/media\/k2\/galleries\/6861\/B.jpg",
  "http:\/\/kashanmap.ir\/media\/k2\/galleries\/6861\/C.jpg"
]

我想将其转换为字符串(以逗号分隔):

http://kashanmap.ir/media/k2/galleries/6861/A.jpg,http://kashanmap.ir/media/k2/galleries/6861/B.jpg,http://kashanmap.ir/media/k2/galleries/6861/C.jpg
let json = JSON(stringLiteral: urls)

但在打印json变量后,它会显示:

[
  "http:\/\/kashanmap.ir\/media\/k2\/galleries\/3156\/A.jpg",
  "http:\/\/kashanmap.ir\/media\/k2\/galleries\/3156\/B.jpg",
  "http:\/\/kashanmap.ir\/media\/k2\/galleries\/3156\/C.jpg",
  "http:\/\/kashanmap.ir\/media\/k2\/galleries\/3156\/D.jpg"
] 

1 个答案:

答案 0 :(得分:0)

尝试使用带逗号分隔符的连接函数

let stringArrayCities = ["Reno", "Austin", "Miami"]
let combinedstringArrayCitiesComma = stringArrayCities.joined(separator: ",")
print(combinedstringArrayCitiesComma)
// prints Reno,Austin,Miami