如何在 nlohmann 的 json 库中获取数组长度?

How can I get the array length in nlohmann's json library?

我正在使用 nlohmann/json 库并想要获取 json 数组的长度。图片我有:

[
"test",
"test2"
]

并想要接收长​​度 (2)。当我尝试 .length() 方法时,它向我显示了这个错误:

using json = using json = class nlohmann::basic_json<>' {aka 'class nlohmann::basic_json<>'} has no member named 'length

那么我怎样才能得到这个库中的长度?

您想在此处使用 myJsonArray.size() 方法。