Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/140.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ Read&;解析JSON文件c++;促进_C++_Json_Boost_Boost Propertytree - Fatal编程技术网

C++ Read&;解析JSON文件c++;促进

C++ Read&;解析JSON文件c++;促进,c++,json,boost,boost-propertytree,C++,Json,Boost,Boost Propertytree,因为在这个问题上已经有很多问题了,我有点担心问。。。但是 我看了很多不同的问题,但没有一个对我有用。我尝试使用此代码,但不起作用: #include "boost/property_tree/ptree.hpp" #include "boost/property_tree/json_parser.hpp" using namespace boost::property_tree; ... std::ifstream jsonFile("test_file.json"); if (!jsonFil

因为在这个问题上已经有很多问题了,我有点担心问。。。但是

我看了很多不同的问题,但没有一个对我有用。我尝试使用此代码,但不起作用:

#include "boost/property_tree/ptree.hpp"
#include "boost/property_tree/json_parser.hpp"
using namespace boost::property_tree;
...
std::ifstream jsonFile("test_file.json");
if (!jsonFile){
    std::cerr << "Error opening file\n";
    return -1;
}
ptree pt;
json_parser::read_json(jsonFile, pt);
for (auto& array_element : pt) {
    for (auto& property : array_element.second) {
        std::cout << property.first << " = " << property.second.get_value<std::string>() << "\n";
    }
}

我无法让它读出
1234
hello world
。事实上,它什么也没做。如何读取
.JSON
文件?

我不完全确定问题出在哪里。它似乎可以工作(一旦您使JSON有效):

#include "boost/property_tree/ptree.hpp"
#include "boost/property_tree/json_parser.hpp"

int main() {
    using boost::property_tree::ptree;

    std::ifstream jsonFile("input.txt");

    ptree pt;
    read_json(jsonFile, pt);

    for (auto & array_element: pt) {
        for (auto & property: array_element.second) {
            std::cout << property.first << " = " << property.second.get_value < std::string > () << "\n";
        }
    }
}
印刷品

number = 1234
string = hello world
number = 5678
string = foo bar

我不完全确定问题出在哪里。它似乎可以工作(一旦您使JSON有效):

#include "boost/property_tree/ptree.hpp"
#include "boost/property_tree/json_parser.hpp"

int main() {
    using boost::property_tree::ptree;

    std::ifstream jsonFile("input.txt");

    ptree pt;
    read_json(jsonFile, pt);

    for (auto & array_element: pt) {
        for (auto & property: array_element.second) {
            std::cout << property.first << " = " << property.second.get_value < std::string > () << "\n";
        }
    }
}
印刷品

number = 1234
string = hello world
number = 5678
string = foo bar

我不完全确定问题出在哪里。它似乎可以工作(一旦您使JSON有效):

#include "boost/property_tree/ptree.hpp"
#include "boost/property_tree/json_parser.hpp"

int main() {
    using boost::property_tree::ptree;

    std::ifstream jsonFile("input.txt");

    ptree pt;
    read_json(jsonFile, pt);

    for (auto & array_element: pt) {
        for (auto & property: array_element.second) {
            std::cout << property.first << " = " << property.second.get_value < std::string > () << "\n";
        }
    }
}
印刷品

number = 1234
string = hello world
number = 5678
string = foo bar

我不完全确定问题出在哪里。它似乎可以工作(一旦您使JSON有效):

#include "boost/property_tree/ptree.hpp"
#include "boost/property_tree/json_parser.hpp"

int main() {
    using boost::property_tree::ptree;

    std::ifstream jsonFile("input.txt");

    ptree pt;
    read_json(jsonFile, pt);

    for (auto & array_element: pt) {
        for (auto & property: array_element.second) {
            std::cout << property.first << " = " << property.second.get_value < std::string > () << "\n";
        }
    }
}
印刷品

number = 1234
string = hello world
number = 5678
string = foo bar


你有一个吗?几乎所有的例子都是@sehe在他的许多答案中给出的,你有一个吗?几乎所有的例子都是@sehe在他的许多答案中给出的,你有一个吗?几乎所有的例子都是@sehe在他的许多答案中给出的,你有一个吗关于此问题的答案是否必须在
.txt
中?我的文件当前是
.json
Erm。这只是我在这里抓住救命稻草的文件名,我不认为这会是一个问题,但我想问你是否可以单独尝试这个例子?干杯。仅供参考,这正是我们所创造的。另请参见是否必须在
.txt
中?我的文件当前是
.json
Erm。这只是我在这里抓住救命稻草的文件名,我不认为这会是一个问题,但我想问你是否可以单独尝试这个例子?干杯。仅供参考,这正是我们所创造的。另请参见是否必须在
.txt
中?我的文件当前是
.json
Erm。这只是我在这里抓住救命稻草的文件名,我不认为这会是一个问题,但我想问你是否可以单独尝试这个例子?干杯。仅供参考,这正是我们所创造的。另请参见是否必须在
.txt
中?我的文件当前是
.json
Erm。这只是我在这里抓住救命稻草的文件名,我不认为这会是一个问题,但我想问你是否可以单独尝试这个例子?干杯。仅供参考,这正是我们所创造的。另见