0

我正在尝试使用 Ankconnect 添加注释,卡片组和模型存在并且字段正确,但我只是返回“null”(并且未添加卡片)。

运行这个 bash 脚本

echo "---------- The deck exists:"

curl localhost:8765 -X POST -d '{
    "action": "getDeckConfig",
    "version": 6,
    "params": {
        "deck": "Foo"
    }
}'


echo "---------- The model exists:"

curl localhost:8765 -X POST -d '{
  "action": "modelFieldNames",
  "version": 6,
  "params": {
    "modelName": "Auto-generated"
  }
}'

echo "---------- But adding a card fails:"

curl localhost:8765 -X POST -d '{
  "action": "addNotes",
  "version": 6,
  "params": {
    "notes": {
      "deckName": "Foo",
      "modelName": "Auto-generated",
      "fields": {
        "Question": "why?",
        "Answer": "because!",
        "Card ID": "foo"
      },
      "options": {
        "allowDuplicate": true
      },
    }
  }
}'

产生这些结果

---------- 套牌存在:

{"result": {"dyn": false, "usn": 82, "timer": 0, "replayq": true, "name": "Default", "id": 1, "lapse": {"mult": 0.0, "minInt": 1, "delays": [10], "leechAction": 0, "leechFails": 8}, "autoplay": true, "rev": {"hardFactor": 1.2, "ivlFct": 1.0, "ease4": 1.3, "perDay": 200, "fuzz": 0.05, "minSpace": 1, "bury": false, "maxIvl": 36500}, "mod": 1560476298, "maxTaken": 60, "new": {"ints": [1, 4, 7], "perDay": 20, "delays": [1, 10], "order": 1, "initialFactor": 2500, "bury": false, "separate": true, "LBGIMinBefore": 1, "LBGIMinAfter": 1, "LBEIMinBefore": 4, "LBEIMinAfter": 4}}, "error": null}

---------- 模型存在:

{"result": ["Question", "Answer", "Card ID"], "error": null}

---------- 但是添加卡失败:

null
4

1 回答 1

0

您的 JSON 中有一些错误。

添加"tags": []到您的每个笔记对象中,因为我所做的测试似乎是强制性的,但可以为空。

这至少会给你一个输出{"result": [null, null, null, null, null], "error": null}

但是你需要修复你的一些领域

  • "addNotes" 接受一个 "notes" 对象数组,但您将单个对象分配给"notes"而不是数组。
  • "modelName"不能"Auto-generated"改成"Basic"
  • "Question"应该"Front"
  • "Answer"应该"Back"

所以这就是你的 curl 调用中的对象应该是这样的:

{
"action": "addNotes",
"version": 6,
"params": {
  "notes": [ 
    {
      "deckName": "Foo",
      "modelName": "Basic",
      "fields": {
        "Front": "why?",
        "Back": "because!",
        "Card ID": "foo"
      },
      "options": {
        "allowDuplicate": true
      },
      "tags": []
    } 
  ]
}
}
于 2019-07-20T07:49:43.837 回答