1: json: cannot unmarshal array into Go value of type main.Catcher or 2: json: cannot unmarshal object into Go value of type main.Crypto4

791 views
Skip to first unread message

m_@li

unread,
May 1, 2018, 10:04:42 AM5/1/18
to golang-nuts
Hi !

 I was searching relevant posts  regarding error "json: cannot unmarshal array into Go value of type main.Catcher" or "json: cannot unmarshal object into Go value of type main.Crypto4". These two error messages are linked to the same program (depends on when I change structure). Actually I have to write/display data on HTML file which will linked through local host port 8080. I could not understand where is the problem I have shared my code and link is attached here.

https://play.golang.org/p/DLOdEGS7hmG (I have quoted main problem with my code instead of write down all the code, means another function where I presented json data through api and it works good, but presentation of data on html file is the problem.

I have created slice like var collect []Crypto4 inside the function and unmarshall data through this variable, but still getting error and html file is not displaying data, instead of getting error which I wrote above in title. It would be so nice to guide me and point out the problem with possible solutions, thanks.

Michael Banzon

unread,
May 1, 2018, 1:14:33 PM5/1/18
to m_@li, golang-nuts

You are declaring your struct as []struct and then using it as ”var collect []Crypto4” effectively doubling the arraynes 😉

 

See this: https://play.golang.org/p/Q3RzNddeVVT

 

And on a side note: Please check your errors – especially if Things doesn’t work – a few err != nil along with fmt.Println’s will save the day 😊

 

--
Michael Banzon
https://michaelbanzon.com/

--
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...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

 

Reply all
Reply to author
Forward
0 new messages