Skip to content

I copy and paste, but error, how to fix? #394

Answered by ii64
donhuvy asked this question in Q&A
Discussion options

You must be logged in to vote

It's a code snippet, you can take a look at this example for a complete one - basically just like encoding/json:

// You can edit this code!
// Click here and start typing.
package main

import (
	"fmt"

	"github.com/bytedance/sonic"
)

// Your schema example
type MySchema struct {
	Name string `json:"name"`
	Age  int    `json:"age,string"`
}

func main() {

	data := []*MySchema{
		{"Foo", 20},
		{"Bar", 21},
		{"Baz", 22},
	}

	jsonData, err := sonic.Marshal(&data)
	if err != nil {
		// handle error, but in this case we are just going to throw it with panic
		panic(err)
	}

	fmt.Println(string(jsonData))
}

Replies: 2 comments 2 replies

Comment options

You must be logged in to vote
1 reply
@donhuvy
Comment options

Answer selected by donhuvy
Comment options

You must be logged in to vote
1 reply
@ii64
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants