1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-11-17 01:53:36 -05:00
v2fly/common/serial/string_list_json.go
2016-01-15 15:23:12 +01:00

26 lines
531 B
Go

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