gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 12:27:06 26 4
gpt4 key购买 nike

我有一个像这样的 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"
]

最佳答案

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

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

关于json - 如何将字符串作为 json 转换为简单字符串 - SwiftyJSON,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44049467/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com