我有一个散列,里面有很多散列,值可能是一个数组,这个数组由许多散列组成,我想打印所有键值对,如果值是数组,那么它必须打印
"pageOfResults": "Array" # I don't want actual array here, I want the string "Array" to be printed.
Run Code Online (Sandbox Code Playgroud)
Of 如果hash跟在后面,那么就需要打印
"PolicyPayment": "Hash"
Run Code Online (Sandbox Code Playgroud)
否则它需要打印键和值
Key -> "CurrencyCode":
Value-> "SGD",
Run Code Online (Sandbox Code Playgroud)
哈希跟随
a={
"PageOfResults": [
{
"CurrencyCode": "SGD",
"IpAddress": nil,
"InsuranceApplicationId": 6314,
"PolicyNumber": "SL10032268",
"PolicyPayment": {
"PolicyPaymentId": 2188,
"PaymentMethod": "GIRO"
},
"InsuranceProductDiscountDetail": nil,
"ProductDetails": {
"Results": [
{
"Id": 8113,
"InsuranceProductId": 382,
"ApplicationProductSelectedId": 62043,
},
"InsuranceProduct": {
"InsuranceProductId": 382,
"ProductCode": "TL70-90",
},
],
},
}
]
}
Run Code Online (Sandbox Code Playgroud)
我编写的程序来打印这些值
a.each do |key,value|
puts "key->" …Run Code Online (Sandbox Code Playgroud) 我有一个像这样的数组
['project','AAA','Division','BBB','TestingType','CCC','Email','abc@gmail.com','def'@gmail.com','efg@gmail.com',...]
Run Code Online (Sandbox Code Playgroud)
电子邮件数量各不相同。并且可能还会有一些内容输入,例如,'project','AAA','Time','2323','Division','BBB','TestingType','CCC'现在您可能已经注意到,输入了Time和2323,所以结果哈希值也必须包含'Time'=>'2323'。但是无论如何,电子邮件将在最后。
我想将此数组转换为这样的哈希
resultHash = {
'project' => 'AAA',
'Division' => 'BBB',
'TestingType' => 'CCC',
'Email' => ['abc@gmail.com', 'def@gmail.com', 'efg@gmail.com']
}
Run Code Online (Sandbox Code Playgroud)
对我而言,这里的困难在于,电子邮件计数每次都不同。有人可以如上所述将这个数组转换为所需的哈希吗?
使用 Ruby selenium-webdriver 3.142.6
\n\n我的测试有效,但在运行开始时它显示警告
\n\nWARN Selenium [DEPRECATION] :driver_path is deprecated. Use :service with an instance of Selenium::WebDriver::Service instead.\nRun Code Online (Sandbox Code Playgroud)\n\n根据 Ruby 文档,Selenium::WebDriver::Service 是一个私有 API。
\n\n在网上搜索与该警告相关的文章,参考了 Capybara、RoR 和 chromedriver-help,但我\xe2\x80\x99m 都没有使用这些内容。我尝试过“gem install webdrivers”,但失败了。
\n\n关于采取的路径有什么建议:忽略弃用消息,或使用私有 Service 类(如果是的话如何使用它),或尝试用 webdrivers 替换 selenium-webdriver,或其他什么?
\n\n这是成功创建 Selenium 驱动程序的代码,但出现警告
\n\nrequire "selenium-webdriver"\nrequire "test/unit"\nrequire "byebug"\n\n...\n\nclass GoogleTest < Test::Unit::TestCase\n\n def setup\n\n case $browser_arg\n when \'chrome\'\n browser = :chrome\n driver_path = \'/selenium_browser_drivers/chromedriver\'\n when \'firefox\'\n browser = :firefox\n driver_path = \'/selenium_browser_drivers/geckodriver\'\n else\n raise ArgumentError.new("Unexpected browser argument \'#{$browser_arg}\'") …Run Code Online (Sandbox Code Playgroud) 我必须将弹性搜索结果解析为特定格式。为此,我需要将搜索结果哈希值放入数组中,我有这个:
hash = {
"ABC": {
"attributes": {
"id": "1",
"from": "test",
"to": "something",
}
},
"XYZ": {
"attributes": {
"id": "1",
"from": "value",
"to": "another value",
}
}
}
Run Code Online (Sandbox Code Playgroud)
我想解决这个问题:
"ABC": [
{
"attributes": {
"id": "1",
"from": "test",
"to": "something",
}
}],
"XYZ": [
{
"attributes": {
"id": "1",
"from": "value",
"to": "another value",
}
}
]
Run Code Online (Sandbox Code Playgroud)
简单地说,哈希值应该是数组。请有人指导我。