mirror of
				https://gitee.com/dromara/mayfly-go
				synced 2025-11-04 00:10:25 +08:00 
			
		
		
		
	
		
			
				
	
	
		
			25 lines
		
	
	
		
			417 B
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			25 lines
		
	
	
		
			417 B
		
	
	
	
		
			Go
		
	
	
	
	
	
package utils
 | 
						|
 | 
						|
import (
 | 
						|
	"encoding/json"
 | 
						|
	"mayfly-go/pkg/global"
 | 
						|
)
 | 
						|
 | 
						|
func Json2Map(jsonStr string) map[string]any {
 | 
						|
	var res map[string]any
 | 
						|
	if jsonStr == "" {
 | 
						|
		return res
 | 
						|
	}
 | 
						|
	_ = json.Unmarshal([]byte(jsonStr), &res)
 | 
						|
	return res
 | 
						|
}
 | 
						|
 | 
						|
func ToJsonStr(val any) string {
 | 
						|
	if strBytes, err := json.Marshal(val); err != nil {
 | 
						|
		global.Log.Error("toJsonStr error: ", err)
 | 
						|
		return ""
 | 
						|
	} else {
 | 
						|
		return string(strBytes)
 | 
						|
	}
 | 
						|
}
 |