开发者

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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜