nlohmann json:检查object是否存在某个键

1.通过find进行检查

#include 
#include 
using namespace std;
using json = nlohmann::json;
 
int main()
{
    json data = R"({
        "name": "xiaoming",
        "age": 10, 
        "parent":   
        [
            {
                "father" : "zhang",
                "age" : 40
            },
            {
                "mother" : "wang",
                "age" : 36
            }
        ]
    })"_json;
 
    auto ifFind = data.find("name");
    if(ifFind != data.end())
    {
        cout<<"name="<

你可能感兴趣的:(C/C++,json)