access_token, ok := result["access_token"] if !ok { fmt.Println("access_token not found") return } // access_token = "bearer " + access_token newJson := map[string]interface{}{ "token": access_token, }上面的go语言代码中access_token前面加"bearer"并保存文件
时间: 2023-05-26 19:06:19 浏览: 118
获取access_token
5星 · 资源好评率100%
你可以使用以下代码将access_token前面加上"bearer"并保存到文件中:
access_token, ok := result["access_token"]
if !ok {
fmt.Println("access_token not found")
return
}
// add "bearer " to the beginning of the access_token
access_token = "bearer " + access_token.(string)
// create a map to hold the new JSON data
newJson := map[string]interface{}{
"token": access_token,
}
// convert the map to a JSON string
newJsonBytes, _ := json.Marshal(newJson)
newJsonString := string(newJsonBytes)
// write the JSON string to a file
err := ioutil.WriteFile("new.json", []byte(newJsonString), 0644)
if err != nil {
fmt.Println("error writing file: ", err)
return
}
阅读全文