1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-12-23 02:26:49 -05:00
v2fly/common/serial/json/string_list.go
2015-12-10 22:08:36 +01:00

22 lines
446 B
Go

package json
import (
"encoding/json"
"errors"
"strings"
)
func UnmarshalStringList(data []byte) ([]string, error) {
var strarray []string
if err := json.Unmarshal(data, &strarray); err == nil {
return strarray, nil
}
var rawstr string
if err := json.Unmarshal(data, &rawstr); err == nil {
strlist := strings.Split(rawstr, ",")
return strlist, nil
}
return nil, errors.New("Unknown format of a string list: " + string(data))
}