This commit is contained in:
aozhiwei 2020-10-28 19:18:47 +08:00
parent f9776ebd7c
commit e21d2e3b5d

View File

@ -24,6 +24,13 @@ func NewXoFromJsonStr(jsonStr string) *XObject {
} }
} }
func NewXoString(val string) *XObject {
p := new(XObject)
p._type = XOT_SIMPLE
p._val = NewXString(val)
return p
}
func (this *XObject) Size() int { func (this *XObject) Size() int {
if (this._type == XOT_ARRAY) { if (this._type == XOT_ARRAY) {
array := this._val.([]*XObject) array := this._val.([]*XObject)
@ -43,6 +50,18 @@ func (this *XObject) GetType() int8 {
return this._type return this._type
} }
func (this *XObject) IsSimple() bool {
return this.GetType() == XOT_SIMPLE
}
func (this *XObject) IsArray() bool {
return this.GetType() == XOT_ARRAY
}
func (this *XObject) IsObject() bool {
return this.GetType() == XOT_OBJECT
}
func (this *XObject) AsXValue() *XValue { func (this *XObject) AsXValue() *XValue {
if this._type == XOT_SIMPLE { if this._type == XOT_SIMPLE {
if this._val == nil { if this._val == nil {
@ -92,6 +111,20 @@ func (this *XObject) HasKey(key string) bool {
} }
} }
func (this *XObject) GetSimpleStr(key string, defVal string) string {
if this.IsObject() {
val := this.At(key)
if val != nil {
if val.IsSimple() {
return val.AsXValue().GetString()
} else {
return defVal
}
}
}
return defVal
}
func (this *XObject) readFromJsonString(data string) bool { func (this *XObject) readFromJsonString(data string) bool {
jsonType := JsonStrType(data) jsonType := JsonStrType(data)
if jsonType == JSON_OBJECT { if jsonType == JSON_OBJECT {