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

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

本文关键字:数组 获取 nlohmann json      更新时间:2023-10-16

我正在使用nlohmann/json-lib,并希望获得json数组的长度。我拥有的图像:

[
"test",
"test2"
]

并且想要接收长度(2(。当我尝试.length((方法时,它显示了以下错误:

usingjson=usingjson=class nlohmann::basic_json<>'{aka"class nlohmann::basic_json<>'"}没有名为"length "的成员

那么我如何获取此库中的长度?

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