I 'd like to unmarshal database records into a struct type. I get the error 
"json: 
cannot unmarshal array into Go value of type main..".

Working example https://play.golang.org/p/keY-3z7lyA
 
I can unmarshal the data to []map[String]string, but cannot reference it 
using key value pairs in the template.

The snippet for code in the template:
     <div class="container">
     {{ range $key, $value := . }} 
        <li><strong>{{ $key }}</strong>: {{ $value }}</li> 
    {{ end }} 
    </div>

The output that I get on the webserver:

- *0*: map[quantity:100 image:1Appleiphone7.jpeg pname:iphone7 price:70000 
puid:d6742e4e-2ad6-43c5-97f4-e8a7b00684e2] 
- *1*: map[image:2SamsungGalaxys7.jpeg pname:SamsungGalaxy7 price:70000 
puid:12d3d8fc-66b6-45f9-a91b-d400b91c32aa quantity:100]



I wanted to display the data as a table by ranging over the key-value 
pairs. But am not able to figure out how.


-- 
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 [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to