From af9fb19b66d5d22ee2eb0d8fbdc4e52afd2823a4 Mon Sep 17 00:00:00 2001 From: "Chen.Zhidong" Date: Thu, 11 Aug 2016 13:58:51 +0800 Subject: [PATCH] add jsonobject and jsonarray judgement --- simplejson.go | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/simplejson.go b/simplejson.go index 27ce986..6d3b8f2 100644 --- a/simplejson.go +++ b/simplejson.go @@ -33,6 +33,26 @@ func New() *Json { } } +// IsArray returns whether the data is JsonArray +func (j *Json) IsArray() bool { + switch j.data.(type) { + case []interface{}: + return true + default: + return false + } +} + +// IsObject returns whether the data is JsonObject +func (j *Json) IsObject() bool { + switch j.data.(type) { + case map[string]interface{}: + return true + default: + return false + } +} + // Interface returns the underlying data func (j *Json) Interface() interface{} { return j.data