Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

encoding/json: Error when use with append #57163

Closed
mcat1997 opened this issue Dec 8, 2022 · 1 comment
Closed

encoding/json: Error when use with append #57163

mcat1997 opened this issue Dec 8, 2022 · 1 comment

Comments

@mcat1997
Copy link

mcat1997 commented Dec 8, 2022

both happend in go1.14 and go1.19

func main() {

var onlyPlatformIDS []int
jsonStr := "[16,803]"
_ = json.Unmarshal([]byte(jsonStr), &onlyPlatformIDS)

platformIDS := append(onlyPlatformIDS, 3)
platformIDS[1] = 804

fmt.Println(onlyPlatformIDS)
fmt.Println(platformIDS)

}

Code like this. It print

[16 804]
[16 804 3]

func main() {

var onlyPlatformIDS []int
//jsonStr := "[16,803]"
//_ = json.Unmarshal([]byte(jsonStr), &onlyPlatformIDS)
onlyPlatformIDS = []int{16, 803}

platformIDS := append(onlyPlatformIDS, 3)
platformIDS[1] = 804

fmt.Println(onlyPlatformIDS)
fmt.Println(platformIDS)

}

Code like this. It print

[16 803]
[16 804 3]

Why?

@seankhliao
Copy link
Member

Unlike many projects, the Go project does not use GitHub Issues for general discussion or asking questions. GitHub Issues are used for tracking bugs and proposals only.

For questions please refer to https://github.com/golang/go/wiki/Questions

@seankhliao seankhliao closed this as not planned Won't fix, can't repro, duplicate, stale Dec 8, 2022
@golang golang locked and limited conversation to collaborators Dec 8, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants