Issue with character when unmarshaling

Hi

When subject has something like " \ " (backslash) it will not unmarsh correctly this. How can I solve this issue.

tnx

type Ticket struct {
	Requestor    string `json:"requestor"`
	Subject      string `json:"subject"`
	Text         string `json:"text"`
	TelefonicaID string `json:"telefonicaid"`
	Circuitid    string `json:"circuitid"`
}



 err = json.Unmarshal(body, &t)

    if err != nil {

    w.WriteHeader(http.StatusUnauthorized)

    w.Write([]byte("Wrong Json!"))

    }

Hi

Is the backslash correctly used in the json you get? \n is newline \t tab and so on and \\ is just a backslash.

Hello

Just backslash in text, for exp for street address.

Can you please show us the raw JSON (or a simplified version of it) that makes problems as well as the the value of err?

Hello guys

text in subject comes like:

{“requestor”:“miha@test.com”,“Subject”:“Test DE ESPA \321A, S.A.U 123321-SITEM-434343”,“Text”:“Pruebas API VENDOR Test”,“telefonicaid”:“INC000001069347”,“circuitid”: “12312321231”}

What I get from unmarshal is nothing, if there is " \ " in subject. If I remove it, then it will be ok and I will get data unmarshal. If I get some error? No, nothing, just data is not unamrshaled correctly.

Yeah, that is invalid JSON, I’ll assume that the quotes are just replaced by the forum software, still you need to escape the backslash:

{
  "requestor": "miha@test.com",
  "Subject": "Test DE ESPA \\321A, S.A.U 123321-SITEM-434343",
  "Text": "Pruebas API VENDOR Test",
  "telefonicaid": "INC000001069347",
  "circuitid": "12312321231"
}

I’m pretty sure you will get somethin in err that is non-nil then…

invalid character ‘3’ in string escape code

Hello

not it is ok.

thank you for this!

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.