This commit is contained in:
aozhiwei 2020-10-26 10:12:41 +08:00
parent f62a41fba7
commit 2a26b63c85
2 changed files with 34 additions and 5 deletions

View File

@ -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{}

View File

@ -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