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

how to add item in slice? #237

Open
cwww3 opened this issue Nov 15, 2021 · 0 comments
Open

how to add item in slice? #237

cwww3 opened this issue Nov 15, 2021 · 0 comments

Comments

@cwww3
Copy link

cwww3 commented Nov 15, 2021

// Is this a right way?
func main() {
	var data = []byte(`[1,2,3]`)
	cnt := 2
	data,_  = jsonparser.Set(data,[]byte("3,4"),fmt.Sprintf("[%v]", cnt))
	fmt.Println(string(data))
	// Output: [1,2,3,4]
	tmp := []int{}
	_ = json.Unmarshal(data,&tmp)
	fmt.Println(len(tmp))
	// Output: 4
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant