Thanks again for the help. Unfortunately it's a third-party API, so I won't 
be able to fix it myself. The full error message is as follows: 

bad value in StructValue for key "image": unrecognized type for Value 
"\"https:\\/\\/ei.isnooth.com\\/multimedia\\/0\\/2\\/8\\/image_787698_square.jpeg\""

I assume the cause for this error is the escaped quotes?

On Tuesday, 15 May 2018 07:08:05 UTC+10, alex....@gmail.com wrote:
>
> In the long term I would investigate what's wrong with the json and if 
> possible fix it at the source.
> Also use this as a reference on what gets mapped to what 
> https://developers.google.com/protocol-buffers/docs/proto3#json
>
> On Tuesday, 15 May 2018 05:03:46 UTC+8, Luke IC wrote:
>>
>> 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:
>>
>>     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)
>>     }
>>
>>
>> Is this fine to do, or is it super inefficient and will cause problems?
>>
>>
>> On Tuesday, 15 May 2018 05:09:04 UTC+10, alex....@gmail.com wrote:
>>>
>>> You need to use the go protobuf json decoder 
>>> https://github.com/golang/protobuf/tree/master/jsonpb
>>>
>>> On Monday, 14 May 2018 11:24:06 UTC+8, Luke IC wrote:
>>>>
>>>> Hi all,
>>>>
>>>> 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.
>>>>
>>>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to