How do I parse JSON data in a template?

asked 2014-02-19 11:52:33 -0500

mr_sm1th gravatar image

updated 2014-02-19 12:41:57 -0500

Given the following data:


$chars = {"abc": {"bbb": "ccc", "ddd": "eee"}, "def": {"bbb": "ccc", "ddd": "eee"}}

How do I extract the values of "def"=>"bbb" and "abc"=>"bbb"? I have the following:


$data = parsejson($chars)
$printer = inline_template("<%- @data.each do |char| -%><%= @char['bbb'] %><%- end -%>")
notify{"$printer":}

With

$printer = inline_template("<%- @data.each do |char| -%><%= @char['bbb'] %><%- end -%>")

I get the following error: Failed to parse inline template: undefined method `[]' for nil:NilClass

With

$printer = inline_template("<%- @data.each do |char| -%><%= @char %><%- end -%>")

I get the following error: Could not intern from text/pson: Could not convert from pson: Could not find relationship target ... (more)

edit retag flag offensive close merge delete