Yes, there could be ways to do it. I could have used Javascript to access
the JSON data values. But couldn't get that to work either. So the easier
thing for me to do was to unmarshal the string again into a
map([string]interface{}) type which is what I finally did to get the code
to work.
Thanks for your reply though.
Rejoy

On Sun, Feb 19, 2017 at 10:04 PM, Hugh S. Myers <hsmy...@gmail.com> wrote:

> The devil sitting on my shoulder tempts me to say "Of course, there is"
> and walk away. That said, by now there must exist code to read JSON (YAML,
> Windows config files, etc.) from a string. It's just a matter of finding
> it.
>
>    - https://gobyexample.com/json
>    - https://blog.golang.org/json-and-go
>
> are just the first two examples that are returned by a Google search which
> mentions 'About 2,890,000 results (0.54 seconds) '. The query was 'go
> code to read JSON'
> HTH and good luck!
>
> --hsm.
>
> On Sun, Feb 19, 2017 at 9:17 AM, Rejoy <rejo...@gmail.com> wrote:
>
>> I am retrieving a set of field values from the Database into an interface
>> type object. One of the field values is a JSON string (say Order detail). I
>> am retrieving it as a string as passing it on to a template and referencing
>> it using {{.orderdetail}}
>> this is the output I get on the client which is a valid json:
>> [{"pid":"d6742e4e-2ad6-43c5-97f4-e8a7b00684e2","image":"1App
>> leiphone7.jpeg","name":"iphone7","price":70000,"count":1},{"
>> pid":"12d3d8fc-66b6-45f9-a91b-d400b91c32aa","image":"
>> 2SamsungGalaxys7.jpeg","name":"SamsungGalaxy7","price":70000,"count":1}]
>> I am not able to access the values in the json using the keys at client
>> side in the template. {{.orderdetails.pid}} does't yield and value.
>> One way would be to unmarshal the string into a map([string]interface{})
>> and then pass on the data to the templates. But was curious if there is a
>> way to access the data using the JSON keys.
>> Thanks
>> Rejoy
>>
>> --
>> 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.
>>
>
>

-- 
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