convert xml attribute (which is a hash) to a Ruby hash
I have a node that looks like this, in the xml file:
<property name="nameA" value="{ "keyA": "valueA", "keyB": "valueB" }"/>
I create the nokogiri object, search it for the value of that node, and get th开发者_Go百科is:
{ "keyA": "valueA", "keyB": "valueB" }
I need to modify valueA. Do I convert this to a Ruby hash, modify it, and then convert it back? How would I do that? Thanks.
This looks like JSON.
gem install json
Then:
require 'json'
hash = JSON.parse('{ "keyA": "valueA", "keyB": "valueB" }')
hash['keyC'] = 'valueC';
attr = hash.to_json
精彩评论