我尝试了不同的 for 循环尝试迭代这个 JSON,但我不知道如何做到这一点。我有一个数字列表,想要将其与每个“数据”对象(例如,Aatrox、Ahri、Akali 等)下的“键”值进行比较,如果数字匹配,则将“名称”值存储在另一个清单。
示例:数字列表 = [266, 166, 123, 283]
266 和 166 将分别匹配 Aatrox 和 Akshan 对象中的“密钥”,因此我想提取该名称并将其存储在列表中。
我知道这个 JSON 主要是通过键值访问而不是索引,所以我不确定如何迭代 for 循环中的所有“数据”对象。
JSON 我引用:
{
"type": "champion",
"format": "standAloneComplex",
"version": "12.2.1",
"data": {
"Aatrox": {
"version": "12.2.1",
"id": "Aatrox",
"key": "266",
"name": "Aatrox",
"title": "the Darkin Blade",
"blurb": "Once honored defenders of Shurima against the Void, Aatrox and his brethren would eventually become an even greater threat to Runeterra, and were defeated only by cunning mortal sorcery. But …Run Code Online (Sandbox Code Playgroud) 每当第二个数字(在这种情况下为y)为负数时,代码都不会给出答案,并最终崩溃。因此(RecursiveMultiply 9 3),(RecursiveMultiply -9 3)工作,(RecursiveMultiply 9 -3)崩溃,(RecursiveMultiply -9 -3)崩溃。
这是我的代码
(define RecursiveMultiply
(lambda (x y)
(if (= y 1)
x
(+ x (RecursiveMultiply x (- y 1))))))
Run Code Online (Sandbox Code Playgroud)