From 243d1ffac87329251cb35343de44b569176eee68 Mon Sep 17 00:00:00 2001 From: what Date: Thu, 4 Dec 2025 14:09:23 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=9C=A8=20rfx.String()=20=E4=B8=AD?= =?UTF-8?q?=EF=BC=8C=E5=85=88=E5=B0=9D=E8=AF=95=E7=94=A8=20cast.ToStringE?= =?UTF-8?q?=20=E5=B0=86=E5=BD=93=E5=89=8D=E5=80=BC=E8=BD=AC=E4=B8=BA?= =?UTF-8?q?=E5=AD=97=E7=AC=A6=E4=B8=B2=EF=BC=8C=E5=A6=82=E6=9E=9C=E5=A4=B1?= =?UTF-8?q?=E8=B4=A5=E5=88=99=E5=A2=9E=E5=8A=A0=E4=BA=86=E4=B8=80=E4=B8=AA?= =?UTF-8?q?=E5=85=9C=E5=BA=95=E9=80=BB=E8=BE=91=EF=BC=9A=E5=B0=9D=E8=AF=95?= =?UTF-8?q?=E4=BD=BF=E7=94=A8=20json.Marshal=20=E5=B0=86=E5=BD=93=E5=89=8D?= =?UTF-8?q?=E5=80=BC=E5=BA=8F=E5=88=97=E5=8C=96=E4=B8=BA=20JSON=20?= =?UTF-8?q?=E5=AD=97=E7=AC=A6=E4=B8=B2=E5=B9=B6=E8=BF=94=E5=9B=9E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- rfx.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/rfx.go b/rfx.go index 2087080..e2ccb67 100644 --- a/rfx.go +++ b/rfx.go @@ -1,6 +1,7 @@ package reflux import ( + "encoding/json" "fmt" "reflect" "strconv" @@ -657,9 +658,14 @@ func (r *rfx) Uint8() uint8 { // String 将当前值转换为 string 类型 func (r *rfx) String() string { - result, err := cast.ToStringE(r.Any()) + data := r.Any() + result, err := cast.ToStringE(data) if err != nil { - panic(fmt.Sprintf("rfx: failed to convert to string: %v", err)) + if b, e := json.Marshal(data); e == nil { + result = string(b) + } else { + panic(fmt.Sprintf("rfx: failed to convert to string: %v", err)) + } } return result }