2016-07-11 2 views
-6

abgerufen werden Ich habe die folgende JSON-Antwort. In diesem JSON habe ich "result" als JSON-Array. Von diesem Array möchte ich den Wert jedes Instanznamens und des entsprechenden Status abrufen und anzeigen. Wie kann ich das machen?wie JSON-Objekt aus dem JSON-Array in Ruby

{ 
    "oradbInstance" : { 
    "oraDBHost" : "", 
    "oraDBPort" : "", 
    "oraDBSid" : "", 
    "oraDBPass" : "", 
    "oraDBJdePass" : "", 
    "oraDBStatus" : "", 
    "oraDBDepComponent" : "", 
    "oraSHARED" : false, 
    "oraADF" : false, 
    "oraOVR" : false, 
    "oradbSchema" : { 
     "oraPROD" : false, 
     "oraPRIST" : false, 
     "oraCRP" : false, 
     "oraDEV" : false 
    }, 
    "oradbDemoSchema" : { 
     "oraPRODDEMO" : false, 
     "oraPRISTDEMO" : false, 
     "oraCRPDEMO" : false, 
     "oraDEVDEMO" : false 
    } 
    }, 
    "result" : [ { 
    "instanceName" : "ent6327", 
    "targetType" : "entserver", 
    "status" : "STOPPED" 
    }, { 
    "instanceName" : "ent790", 
    "targetType" : "entserver", 
    "status" : "STOPPED" 
    }, { 
    "instanceName" : "920_ENT_6017", 
    "targetType" : "entserver", 
    "status" : "RUNNING" 
    }, { 
    "instanceName" : "ent7943", 
    "targetType" : "entserver", 
    "status" : "STOPPED" 
    }, { 
    "instanceName" : "920_JAS_8082", 
    "targetType" : "webserver", 
    "status" : "RUNNING" 
    }, { 
    "instanceName" : "ENT6547", 
    "targetType" : "entserver", 
    "status" : "STOPPED" 
    }, { 
    "instanceName" : "ent4563", 
    "targetType" : "entserver", 
    "status" : "STOPPED" 
    }, { 
    "instanceName" : "ent6021", 
    "targetType" : "entserver", 
    "status" : "RUNNING" 
    }, { 
    "instanceName" : "AIS_0005", 
    "targetType" : "restserver", 
    "status" : "RUNNING" 
    }, { 
    "instanceName" : "DEN00KNL_DEP_920", 
    "targetType" : "depserver", 
    "status" : "RUNNING" 
    }, { 
    "instanceName" : "wls1213", 
    "targetType" : "owl_1212", 
    "status" : "RUNNING" 
    }, { 
    "instanceName" : "HTML_8792", 
    "targetType" : "webserver", 
    "status" : "RUNNING" 
    }, { 
    "instanceName" : "home", 
    "targetType" : "mgmtconsole", 
    "status" : "RUNNING" 
    }, { 
    "instanceName" : "ent6060_Win", 
    "targetType" : "entserver", 
    "status" : "RUNNING" 
    }, { 
    "instanceName" : "RTE_0004", 
    "targetType" : "rteserver", 
    "status" : "RUNNING" 
    }, { 
    "instanceName" : "ent6363", 
    "targetType" : "entserver", 
    "status" : "STOPPED" 
    } ] 
} 

Irgendwelche Vorschläge hilfsbereit

+0

Willkommen bei Stack-Überlauf. Wir möchten Ihren Versuch sehen, dieses Problem zu lösen, anstatt Code für Sie zu schreiben. Bitte lesen Sie "[fragen]" einschließlich der verlinkten Seiten und "[mcve]". –

Antwort

0
require 'json' 
JSON.parse(input)['result'].map do |h| 
    [h['instanceName'], h['status']] 
end.to_h 
#⇒ { 
#  "920_ENT_6017" => "RUNNING", 
#  "920_JAS_8082" => "RUNNING", 
#   "AIS_0005" => "RUNNING", 
# "DEN00KNL_DEP_920" => "RUNNING", 
#   "ENT6547" => "STOPPED", 
#   "HTML_8792" => "RUNNING", 
#   "RTE_0004" => "RUNNING", 
#   "ent4563" => "STOPPED", 
#   "ent6021" => "RUNNING", 
#  "ent6060_Win" => "RUNNING", 
#   "ent6327" => "STOPPED", 
#   "ent6363" => "STOPPED", 
#   "ent790" => "STOPPED", 
#   "ent7943" => "STOPPED", 
#    "home" => "RUNNING", 
#   "wls1213" => "RUNNING" 
# } 
+0

kann ich diese Ausgabe im Tabellenformat mit Überschrift Instanzname und Status –

+0

drucken Ja, das können Sie definitiv. – mudasobwa