{
"Restricted_parameters":
{
"abcd"
"efgh"
"ijkl"
"mnop"
}
}
我是关于json文件和解析它的新手,在我当前的大学项目中,当我正在解析json文件时它会给出错误
任何人都可以让我知道如何解析上面的json文件
我也在使用JSON解析器API
Jason_parser_edf::Jason_parser_edf()
{
Json_parser file_parser;
// Create empty property tree object
using boost::property_tree::ptree;
ptree pt;
uint32_t nb = 0;
std::string // const std::string restricted_parameters = "Restricted_parameters";
file_parser.open_json_file(current_file_path, &pt);
ptree::const_iterator end = pt.end();
for (ptree::const_iterator it = pt.begin(); it != end; ++it)
{
BOOST_FOREACH( ptree::value_type const& v, pt.get_child(it->first) ) // parasoft-suppress MISRA2008-6_4_1 "BOOST library" // parasoft-suppress NAMING-33 "BOOST library" // parasoft-suppress BD-PB-CC "BOOST library" // parasoft-suppress MISRA2008-6_3_1 "BOOST library"
{
// Getting additional fields
std::string additional_field_name = v.second.get<std::string>("Restricted_parameters");
cout << additional_field_name << endl;
}
}
// second way I am trying
for (auto & array_element: pt) {
for (auto & property: array_element.second) {
std::cout << property.first << endl;
}
}
// db_conf_structure.dump();
}
答案 0 :(得分:1)
这不是JSON的有效格式,您必须始终记住具有对键:值
{
"Restricted_parameters":
{
"abcd": "val1",
"efgh": "val2",
"ijkl": "val3",
"mnop": "val4"
}
}
或使用数组
{
"Restricted_parameters":
[
"abcd",
"efgh",
"ijkl",
"mnop"
]
}
答案 1 :(得分:0)
JSON无效。数组通过方括号初始化,您需要在项目之间使用逗号。
{
"Restricted_parameters":
[
"abcd",
"efgh",
"ijkl",
"mnop"
]
}