繁体   English   中英

JsonCpp:未定义对“ Json :: Value :: operator [](int)const”的引用

[英]JsonCpp: Undefined reference to `Json::Value::operator[](int) const'

我正在尝试将JsonCpp与该示例代码一起使用

string json_example = "{\"array\":[\"item1\", \"item2\"], \"not an array\":\"asdf\"}";


    // Let's parse it
    Json::Value root;
    Json::Reader reader;


    //Parsing of something. In example do parsing of json_example string.
    bool parsedSuccess = reader.parse(json_example, root, false);

    if (!parsedSuccess) {
        // report to the user the failure and their locations in the document.
        cout  << "Failed to parse JSON" << endl << reader.getFormatedErrorMessages() << endl;
        return 1;
    }

    // Let's extract the array that is contained inside the root object
    const Json::Value array = root["array"];

    // And print its values
    for (int index = 0; index < array.size(); ++index) {   // Iterates over the sequence elements.
        cout << "Element " << index << " in array: " << array[index].asString() << endl;
    }

    // Lets extract the not array element contained in the root object and print its value
    cout << "Not an array: " << root["not an array"] << endl;

    // If we want to print JSON is as easy as doing:
    cout << "Json Example pretty print: " << endl << root.toStyledString() << endl;

    return 0;

但我在此“ ..array [index] .asString ...”上收到此错误

Undefined reference to `Json::Value::operator[](int) const'

有人可以帮我吗?

Tnx为您解答...所以解决方案正在改变这一点

 for (int index = 0; index < array.size(); ++index) {   // Iterates over the sequence elements.
    cout << "Element " << index << " in array: " << array[index].asString() << endl;
}

 for (unsigned int index = 0; index < array.size(); ++index) {   // Iterates over the sequence elements.
    cout << "Element " << index << " in array: " << array[index].asString() << endl;
}

再见

我认为您没有包括描述您的json.h库文件的jsoncpp.cpp文件。 您必须使用Pythot使用命令python amalgamate.py生成它,然后将其包含到您的项目中

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM