37 lines
		
	
	
		
			951 B
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			37 lines
		
	
	
		
			951 B
		
	
	
	
		
			Go
		
	
	
	
	
	
package jsonhelper
 | 
						|
 | 
						|
import (
 | 
						|
	"github.com/bytedance/sonic"
 | 
						|
	jsonIterator "github.com/json-iterator/go"
 | 
						|
	"github.com/vmihailenco/msgpack/v5"
 | 
						|
)
 | 
						|
 | 
						|
var (
 | 
						|
	IJson = jsonIterator.ConfigCompatibleWithStandardLibrary
 | 
						|
	// Marshal is exported by common package.
 | 
						|
	Marshal = IJson.Marshal
 | 
						|
	// Unmarshal is exported by common package.
 | 
						|
	Unmarshal = IJson.Unmarshal
 | 
						|
	// MarshalIndent is exported by common package.
 | 
						|
	MarshalIndent = IJson.MarshalIndent
 | 
						|
	// NewDecoder is exported by common package.
 | 
						|
	NewDecoder = IJson.NewDecoder
 | 
						|
	// NewEncoder is exported by common package.
 | 
						|
	NewEncoder = IJson.NewEncoder
 | 
						|
 | 
						|
	// MarshalMsgPack msgpack方式序列化
 | 
						|
	MarshalMsgPack = msgpack.Marshal
 | 
						|
	// msgpack方式反序列化
 | 
						|
	UnmarshalMsgPack  = msgpack.Unmarshal
 | 
						|
	NewDecoderMsgPack = msgpack.NewDecoder
 | 
						|
	NewEncoderMsgPack = msgpack.NewEncoder
 | 
						|
)
 | 
						|
 | 
						|
func ToJsonString(v interface{}) string {
 | 
						|
	if result, err := sonic.Marshal(v); err == nil {
 | 
						|
		return string(result)
 | 
						|
	}
 | 
						|
 | 
						|
	return ""
 | 
						|
}
 |