From 2a26b63c85c9e17926fd0bf2689362c817cbbf25 Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Mon, 26 Oct 2020 10:12:41 +0800 Subject: [PATCH] 1 --- xobject.go | 15 ++++++++++----- xvalue.go | 24 ++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 5 deletions(-) diff --git a/xobject.go b/xobject.go index 3fb1aaa..e8ec51f 100644 --- a/xobject.go +++ b/xobject.go @@ -15,6 +15,15 @@ type XObject struct { _val interface{} } +func NewXoFromJsonStr(jsonStr string) *XObject { + p := new(XObject) + if p.readFromJsonString(jsonStr) { + return p + } else { + return nil + } +} + func (this *XObject) Size(key interface{}) int { if (this._type == XOT_ARRAY) { array := this._val.(*[]*XObject) @@ -83,11 +92,7 @@ func (this *XObject) HasKey(key string) bool { } } -func (this *XObject) ReadFromJsonFile(fileName string) bool { - return false -} - -func (this *XObject) ReadFromJsonString(data string) bool { +func (this *XObject) readFromJsonString(data string) bool { jsonType := JsonStrType(data) if jsonType == JSON_OBJECT { var rawJson map[string]interface{} diff --git a/xvalue.go b/xvalue.go index 04befc8..185ccc1 100644 --- a/xvalue.go +++ b/xvalue.go @@ -54,6 +54,30 @@ func (this *XValue) IsUndefined() bool { return this._type == XVT_UNDEFINED } +func (this *XValue) IsInt() bool { + return this._type == XVT_INT +} + +func (this *XValue) IsFloat() bool { + return this._type == XVT_INT +} + +func (this *XValue) IsNumber() bool { + return this.IsInt() || this.IsFloat() +} + +func (this *XValue) IsString() bool { + return this._type == XVT_STRING +} + +func (this *XValue) IsBytes() bool { + return this._type == XVT_BYTES +} + +func (this *XValue) IsUserData() bool { + return this._type == XVT_USERDATA +} + func (this *XValue) SetUInt8(val uint8) *XValue { this.SetInt64(int64(val)) return this