How to Unmarshal json string

I have the following code:

a := alert{}  //structure I have with a few fields and all string types
tmp := req.FormValue("payload")  //grab POST var from call
json.Unmarshal( []byte(tmp), &a ); //unmarshal and put fields into alert struct

I’ve seen examples all over using this syntax and the tmp var does contain my json string as I’d expect. But unmarshal command results in an empty alert struct and I get no errors.

How would I get this to work properly as I’m obviously missing something.

Thanks,

Unmarshall can only work on exposed types and exposed fields.

ok, so still trying to get used to the goofiness of captial letters. So for those interested I changed my structure fields to have a capital letter as the first letter and all is good now.

Thanks,

1 Like

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