go icon indicating copy to clipboard operation
go copied to clipboard

Bug: jsoniter.UnmarshalFromString

Open ydg941020 opened this issue 2 months ago • 0 comments

type TextStyle struct {
	FontFamily string `json:"fontFamily"`
	FontSize int32 `json:"fontSize"`
	TextAlign string `json:"textAlign"`
	TextColor string `json:"textColor"`
	FontStyle string `json:"fontStyle"`
	IsBold bool `json:"isBold"`
	IsItalic bool `json:"isItalic"`
	Underline string `json:"underline"`
}

func Test_json(t *testing.T) {
	res := &TextStyle{}
	style := `{"isBold": 0, "fontSize": 136, "isItalic": 0, "fontStyle": "", "textAlign": "center", "textColor": "rgba(0,0,0,1)", "fontFamily": "ABeeZee-regular"}`
	_ = jsoniter.UnmarshalFromString(style, res)
	t.Logf("res=%+v", res) // res=&{FontFamily: FontSize:36 TextAlign: TextColor: FontStyle: IsBold:false IsItalic:false Underline:}

	_ = json.Unmarshal([]byte(style), res)
	t.Logf("res=%+v", res) // res=&{FontFamily:ABeeZee-regular FontSize:136 TextAlign:center TextColor:rgba(0,0,0,1) FontStyle: IsBold:false IsItalic:false Underline:}

}

OutPut: 
// res=&{FontFamily: FontSize:36 TextAlign: TextColor: FontStyle: IsBold:false IsItalic:false Underline:}
// res=&{FontFamily:ABeeZee-regular FontSize:136 TextAlign:center TextColor:rgba(0,0,0,1) FontStyle: IsBold:false IsItalic:false Underline:}

ydg941020 avatar Nov 17 '25 09:11 ydg941020