I'm creating a microservice in Go, using protocol buffers and gRPC.
It interacts with a third-party API (Snooth) and I'm trying to unmarshal
the JSON response into a protobuf struct I've created, using the proto package.
Unmarshalling returns an unexpected EOF error.
I've summed up the details in full on this question at Stack Overflow: https://stackoverflow.com/questions/50314476/why-does-unmarshalling-this-api-response-return-an-unexpected-eof
In addition to the information posted there, I've also tried using strconv.Unquote before unmarshalling in line with the idea that the escaped characters in the API response are causing a double-encode. But this didn't work either.
Any help would be greatly appreciated as I've been stuck on this for a while now and feel there's something simple I'm missing.
Thanks.
It DOES parse with then encoding/json package: https://play.golang.org/p/IQzMm2tDI7w
The protoc-generated code's Unmarshal parses a Protocol Buffers encoded byte stream, NOT JSON!
meta:<results:1489449 returned:15 status:1 > wines:<> wines:<> wines:<> wines:<> wines:<> wines:<> wines:<> wines:<> wines:<> wines:<> wines:<> wines:<> wines:<> wines:<> wines:<> resJson, err := ioutil.ReadAll(res.Body)
j := make(map[string]interface{})
jbytes, err := json.Marshal(j)
result := &pb.Response{}
r := strings.NewReader(string(jbytes))
if err := jsonpb.Unmarshal(r, result); err != nil {
panic(err)
}bad value in StructValue for key "image": unrecognized type for Value "\"https:\\/\\/ei.isnooth.com\\/multimedia\\/0\\/2\\/8\\/image_787698_square.jpeg\""body, _ := ioutil.ReadAll(res.Body)
fmt.Println(string(body))Thanks a lot, I went back and gave jsonpb a go and finally got it unmarshalling as desired.To do so though I had to unmarshal and marshal the response with the regular json library first, in order to get around some escaped values in the response (I was receiving a 'bad value in Struct' error: