我有一个看起来像这样的json文件:
{
"Results": [
{
"Lookup": null,
"Result": {
"Paths": [
{
"Domain": "VALUE1.LTD",
"Url": "",
"Text1": "",
"Modules": [
{
"Name": "VALUE",
"Tag": "VALUE",
"FirstDetected": "1111111111",
"LastDetected": "11111111111"
},
{
"Name": "VALUE",
"Tag": "VALUE",
"FirstDetected": "111111111111",
"LastDetected": "11111111111111"
}
]
}
]
}
}
]
}
Run Code Online (Sandbox Code Playgroud)
如何仅打印域并仅访问ruby中的module.names并将module.names打印到控制台:
#!/usr/bin/ruby
require 'rubygems'
require 'json'
require 'pp'
json = File.read('input.json')
Run Code Online (Sandbox Code Playgroud)
有没有人知道ruby和json有什么好资源给新来的人?
我从我的json文件中提取一些信息,格式如下:
{
"name": "value",
"website": "https://google.com",
"type" : "money",
"some": "0",
"something_else": "0",
"something_new": "0",
"test": [
{"Web" : "target1.com", "type" : "2" },
{"Web" : "target2.com", "type" : "3" },
{"Web" : "target3.com", "type" : "3" },
{"Web" : "target3.com", "type" : "3" }
]
}
Run Code Online (Sandbox Code Playgroud)
我知道jq -r .test[].Web会输出:
target1.com
target2.com
target3.com
Run Code Online (Sandbox Code Playgroud)
但是如果我只想获得类型为3的值意味着输出只显示target2.com和target3.com
我有以下代码:
(define (howMany list)
(if (null? list)
0
(+ 1 (howMany (cdr list)))))
Run Code Online (Sandbox Code Playgroud)
如果我们执行以下操作:(howMany '(1 2 3 (4 5)))我们将得到 4 结果。我该如何做才能计算列表中的整数数量。这意味着同样的问题将返回 5 作为答案,而不是 4。
假设我们在文本文件中有一个IP地址/块列表:
123.123.0.0
111.111.111.0
101.101.0.111
Run Code Online (Sandbox Code Playgroud)
现在我想打印出所有可能的IP地址.例如,对于上面列表中的第一项:
123.123.0.0
123.123.0.1
123.123.0.2
123.123.0.3
[...]
123.123.0.255
123.123.1.1
123.123.1.2
[...]
123.123.255.255
Run Code Online (Sandbox Code Playgroud)
我在阅读和编写文件等方面不需要帮助.只是想不出如何打印出该块/范围内的每个可能的IP地址.有可能做一个块并用x替换0并保持| x |,并在1-255之间打印x?