From 88d27fae0616afe2cf45b7914682096289c48550 Mon Sep 17 00:00:00 2001
From: hoteas <hoteas@958342c6-dd43-9346-b63c-019703d72853>
Date: Thu, 9 Nov 2017 10:15:55 +0000
Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0slice?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 trunk/src/go.hoteas.com/hotime/db.go       |  2 +-
 trunk/src/go.hoteas.com/hotime/objtoobj.go | 22 ++++++++++++++--------
 trunk/src/go.hoteas.com/hotime/slice.go    |  9 ---------
 3 files changed, 15 insertions(+), 18 deletions(-)

diff --git a/trunk/src/go.hoteas.com/hotime/db.go b/trunk/src/go.hoteas.com/hotime/db.go
index 020668a..95b60e2 100644
--- a/trunk/src/go.hoteas.com/hotime/db.go
+++ b/trunk/src/go.hoteas.com/hotime/db.go
@@ -598,7 +598,7 @@ func (this *HoTimeDB) varCond(k string, v interface{}) (string, []interface{}) {
 		case "[~]":
 			k = strings.Replace(k, "[~]", "", -1)
 			where += "`" + k + "` LIKE ? "
-			v = "%" + v.(string) + "%"
+			v = "%" + ObjToStr(v) + "%"
 			res = append(res, v)
 		default:
 			def = true
diff --git a/trunk/src/go.hoteas.com/hotime/objtoobj.go b/trunk/src/go.hoteas.com/hotime/objtoobj.go
index db1f3e2..1008c71 100644
--- a/trunk/src/go.hoteas.com/hotime/objtoobj.go
+++ b/trunk/src/go.hoteas.com/hotime/objtoobj.go
@@ -4,7 +4,7 @@ import (
 	"encoding/json"
 	"errors"
 	"strconv"
-	"strings"
+	//"strings"
 )
 
 //仅限于hotime.Slice
@@ -68,6 +68,9 @@ func ObjToSlice(obj interface{}, e ...*Error) Slice {
 			for i := 0; i < len(obj.([]string)); i++ {
 				v = append(v, obj.([]string)[i])
 			}
+		case string:
+			v = Slice{}
+			err = json.Unmarshal([]byte(obj.(string)), &v)
 
 		default:
 			v = nil
@@ -255,8 +258,8 @@ func StrToMap(string string) Map {
 
 //转换为Slice
 func StrToSlice(string string) Slice {
-	data := Slice{}
-	data.JsonToSlice(string)
+
+	data := ObjToSlice(string)
 
 	return data
 }
@@ -266,10 +269,13 @@ func StrArrayToJsonStr(a string) string {
 
 	if len(a) != 0 {
 		if a[0] == ',' {
-			a = Substr(a, 1, len(a))
+			a = Substr(a, 1, len(a)-1)
 		}
-		a = strings.Replace(a, ",", `","`, -1)
-		a = `["` + a + `"]`
+		if a[len(a)-1] == ',' {
+			a = Substr(a, 1, len(a)-2)
+		}
+		//a = strings.Replace(a, ",", `,`, -1)
+		a = `[` + a + `]`
 	} else {
 		a = "[]"
 	}
@@ -278,12 +284,12 @@ func StrArrayToJsonStr(a string) string {
 
 //字符串数组: a1,a2,a3转["a1","a2","a3"]
 func JsonStrToStrArray(a string) string {
-	a = strings.Replace(a, `"`, "", -1)
+	//a = strings.Replace(a, `"`, "", -1)
 	if len(a) != 0 {
 		a = Substr(a, 1, len(a)-2)
 	}
 
-	return "," + a
+	return "," + a + ","
 }
 
 //字符串转int
diff --git a/trunk/src/go.hoteas.com/hotime/slice.go b/trunk/src/go.hoteas.com/hotime/slice.go
index a368001..15fb84e 100644
--- a/trunk/src/go.hoteas.com/hotime/slice.go
+++ b/trunk/src/go.hoteas.com/hotime/slice.go
@@ -1,7 +1,6 @@
 package hotime
 
 import (
-	"encoding/json"
 	"errors"
 )
 
@@ -65,11 +64,3 @@ func (this Slice) Put(key int, value interface{}) {
 func (this Slice) ToJsonString() string {
 	return ObjToStr(this)
 }
-
-
-
-func (this Slice) JsonToSlice(jsonStr string) {
-
-	json.Unmarshal([]byte(jsonStr), &this)
-
-}