How to Unmarshal json string


(Glenn Hancock) #1

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,


(Norbert Melzer) #2

Unmarshall can only work on exposed types and exposed fields.


(Glenn Hancock) #3

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,