golang []string 转jsonarray
时间: 2023-11-25 11:06:12 浏览: 138
可以使用标准库中的`encoding/json`包来实现。具体的代码如下:
```go
package main
import (
"encoding/json"
"fmt"
)
func main() {
strArr := []string{"apple", "banana", "orange"}
jsonArr, err := json.Marshal(strArr)
if err != nil {
fmt.Println("Error:", err)
return
}
fmt.Println(string(jsonArr))
}
```
输出结果为:
```
["apple","banana","orange"]
```
这样就将`[]string`类型的`strArr`转换成了JSON数组格式。
阅读全文
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![.zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![.zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)