内部にハッシュを含むいくつかの配列に苦労しています。それらを新しいオブジェクトに解析したいのですが、これを行う方法がわかりません。
データは次のとおりです。
[
{
"name" => "itemHref",
"value" => "https://192.168.75.145:8281/api/workflows/16da1fa1-7c8b-4602-8d53-17fc5e1fa3ff/"
},
{
"name" => "id",
"value" => "16da1fa1-7c8b-4602-8d53-17fc5e1fa3ff"
},
{
"name" => "categoryName",
"value" => "FinanzInformatik"
},
{
"name" => "canExecute",
"value" => "true"
},
{
"name" => "categoryHref",
"value" => "https://192.168.75.145:8281/api/catalog/System/WorkflowCategory/ff8080813b90a145013b90cac51b0006/"
},
{
"name" => "description",
"value" => "bekommt alle VMs"
},
{
"name" => "name",
"value" => "getAllVms"
},
{
"name" => "type",
"value" => "Workflow"
},
{
"name" => "canEdit",
"value" => "true"
}
]
そして、ここに私のコードがあります:
require 'rest-client'
require 'json'
class Workflow
def initialize(itemHref, id, categoryName, canExecute, categoryHref, description, name, type, canEdit)
@itemHref = itemHref
@id = id
@categoryName = categoryName
@canExecute = canExecute
@categoryHref = categoryHref
@description = description
@name = name
@type = type
@canEdit = canEdit
end
end
json_string = RestClient.get( "http://vcoadmin:vcoadmin@192.168.75.145:8280/api/workflows", :content_type => 'application/json', :accept => 'application/json')
parsed = JSON.parse(json_string)
parsed.each do |a, b|
if(b.class == Array)
b.flatten.each do |c|
p c['attributes']
#c['attributes'].each
{
|f| p f['name'], f['value'] }
end
end
end
ハッシュ値をオブジェクトに入れるにはどうすればよいですか? 値の識別子である「名前」に基づいて何かを考えます。
何か案は?