【发布时间】:2021-12-31 21:13:43
【问题描述】:
我正在使用 API 将所有宏返回给我,我正在尝试返回所有“宏”,其中“动作”包含与我的正则表达式模式匹配的“值”,我将在下面链接。
我尝试了以下方法和其他方法,但它返回的当前值为零。任何提示表示赞赏
macros["value"].select { |m| m['key'] == 'value' }.first['/^DE([0-9a-zA-Z]\s?){20}$/gm']
API结果sn-p:
jsObj
=> {"macros"=>
[{"url"=>"https://s/1900002708354.json",
"id"=>1900002708354,
"title"=>"Append Signature",
"active"=>true,
"updated_at"=>"2021-10-22T14:11:15Z",
"created_at"=>"2021-10-22T14:11:15Z",
"position"=>10001,
"description"=>"This macro appends a signature to the message ",
"actions"=>[{"field"=>"comment_value_html", "value"=>"<p>Mit besten Grüßen,</p><p>{{current_user.name}} [{{ticket.account}}] <br></p><p><br></p><p>{{dc.signature_email}}<br></p><p><br></p>"}],
"restriction"=>nil},
{"url"=>"949.json",
"id"=>59071949,
"title"=>"information",
"description"=>nil,
"actions"=>[{"field"=>"priority", "value"=>"low"}, {"field"=>"comment_value", "value"=>"DE89370400440532013000" "DE89 3704
0044 0532 0130 00"
"}],
"restriction"=>nil},
期望的结果:
{
"macros": [
{
"url": "x.json",
"id": 1900002708354,
"actions": [
{
"field": "comment_value_html",
"value": "DE89 3704 0044 0532 0130 00"
}
],
"restriction": null
},
{
"url": "x.json",
"id": 59071949,
"actions": [
{
"field": "priority",
"value": "low"
},
{
"field": "comment_value",
"value": "DE89 3704 0044 0532 0130 00
"
}
],
"restriction": null
},
【问题讨论】:
-
无论何时给出示例,请显示所需的结果,此处为有效的 Ruby 对象(例如,数组或哈希)。请注意,
"IBANS"不会出现在 JSON 中(仅"IBAN")。 “宏”是什么意思? -
@CarySwoveland 感谢您的提示,我已经更新了所需的结果。在这种情况下,一个宏在各种文本模板中,如上面的 API 响应所示,上面我有一个包含 3 个宏的 sn-p。
-
还是有点不清楚。也许您需要的只是获取
macros,其中actions包含与您的模式匹配的value?见ideone.com/JWT8Xr -
@WiktorStribiżew 是的,这正是我想要的,我会更新以使其更清晰,谢谢。