Skip to content

解析[]byte出现乱码(同时并不希望自动base64decode) #244

Closed
@pwtitle

Description

@pwtitle

type Message struct {
URL string json:"url"
Body []byte json:"body"
Strategy []int json:"strategy"
Method string json:"method"
// Headers []Header json:"headers"
Handler string json:"handler,omitempty"
Referer string json:"referer,omitempty"
Headers map[string]string json:"headers"
}

.....
body := []byte({"url":"abc.com","method":"PUT","body":"asdasdfsdfsfsfasfd==","strategy":[10,11,12,13,14,15,16,17,18,19,20],"headers":[],"referer":null,"handler":"f331db77be59f18eab9ada6924e04a32"})

var json = jsoniter.ConfigCompatibleWithStandardLibrary
extra.RegisterFuzzyDecoders()
err := json.Unmarshal(body, &message)
if err != nil {
	fmt.Println(err);
}
fmt.Printf("\r\n%s\r\n", message.Body);

......
结果是:j�Z���u����}

如果
body := []byte({"url":"abc.com","method":"PUT","body":"eyJ1c2VybmFtZSI6InRlc3RlciIsInBhc3N3b3JkIjoiMTIzNDU2In0=","strategy":[10,11,12,13,14,15,16,17,18,19,20],"headers":[],"referer":null,"handler":"f331db77be59f18eab9ada6924e04a32"})

则结果为:{"username":"tester","password":"123456"}

但是我并不想jsoniter帮我自动解码呀。

另外如果body的内容是比较长的base64内容,这返回:

main.Message.Method: Body: decode base64: illegal base64 data at input byte 230, error found in #10 byte of ...|wIn19fX0=","method":|..., bigger context ...|0aW9uIjoiMC4wMCIsInJldmVudWUiOiIyODAwLjAwIn19fX0=","method":"POST","strategy":[30,300],"headers":{"C|...

这个错误。

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions