1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-12-22 10:08:15 -05:00
v2fly/common/collect/string_list_json.go

26 lines
511 B
Go
Raw Normal View History

2016-01-15 09:23:12 -05:00
// +build json
2016-05-24 16:41:51 -04:00
package collect
2016-01-15 09:23:12 -05:00
import (
"encoding/json"
"errors"
"strings"
)
2016-05-24 16:41:51 -04:00
func (this *StringList) UnmarshalJSON(data []byte) error {
2016-01-15 09:23:12 -05:00
var strarray []string
if err := json.Unmarshal(data, &strarray); err == nil {
2016-05-24 16:41:51 -04:00
*this = *NewStringList(strarray)
2016-01-15 09:23:12 -05:00
return nil
}
var rawstr string
if err := json.Unmarshal(data, &rawstr); err == nil {
strlist := strings.Split(rawstr, ",")
2016-05-24 16:41:51 -04:00
*this = *NewStringList(strlist)
2016-01-15 09:23:12 -05:00
return nil
}
return errors.New("Unknown format of a string list: " + string(data))
}