- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试使用 Boost 的 property_tree 解析器和 C++11 代码来解析 JSON(我的系统是带有 gcc 4.7.2 和 Boost 1.49 的 Debian Wheezy)。我基于 Serializing and deserializing json with boost 尝试了以下代码:
#include <map>
#include <sstream>
#include <boost/property_tree/ptree.hpp>
#include <boost/property_tree/json_parser.hpp>
using boost::property_tree::ptree; using boost::property_tree::read_json; using boost::property_tree::write_json;
void example() {
// Write json.
ptree pt;
pt.put ("foo", "bar");
std::ostringstream buf;
write_json (buf, pt, false);
std::string json = buf.str(); // {"foo":"bar"}
// Read json.
ptree pt2;
std::istringstream is (json);
read_json (is, pt2);
std::string foo = pt2.get<std::string> ("foo");
}
g++ -std=c++03 -c' everything is fine. However, I also want to use C++11 features (which the code in the linked thread actually does!). But with
编译它g++ -std=c++11 -c' 我得到编译错误:
In file included from /usr/include/boost/property_tree/json_parser.hpp:14:0,
from test.cpp:4:
/usr/include/boost/property_tree/detail/json_parser_read.hpp: In instantiation of ‘void boost::property_tree::json_parser::context<Ptree>::a_literal_val::operator() (boost::property_tree::json_parser::context<Ptree>::It, boost::property_tree::json_parser::context<Ptree>::It) const [with Ptree = boost::property_tree::basic_ptree<std::basic_string<char>, std::basic_string<char> >; boost::property_tree::json_parser::context<Ptree>::It = __gnu_cxx::__normal_iterator<char*, std::vector<char, std::allocator<char> > >]’:
/usr/include/boost/spirit/home/classic/core/scanner/scanner.hpp:148:13: required from ‘static void boost::spirit::classic::attributed_action_policy<boost::spirit::classic::nil_t>::call(const ActorT&, boost::spirit::classic::nil_t, const IteratorT&, const IteratorT&) [with ActorT = boost::property_tree::json_parser::context<boost::property_tree::basic_ptree<std::basic_string<char>, std::basic_string<char> > >::a_literal_val; IteratorT = __gnu_cxx::__normal_iterator<char*, std::vector<char, std::allocator<char> > >]’
/usr/include/boost/spirit/home/classic/core/scanner/scanner.hpp:163:13: required from ‘void boost::spirit::classic::action_policy::do_action(const ActorT&, AttrT&, const IteratorT&, const IteratorT&) const [with ActorT = boost::property_tree::json_parser::context<boost::property_tree::basic_ptree<std::basic_string<char>, std::basic_string<char> > >::a_literal_val; AttrT = boost::spirit::classic::nil_t; IteratorT = __gnu_cxx::__normal_iterator<char*, std::vector<char, std::allocator<char> > >]’
...
test.cpp:20:1: required from here
/usr/include/boost/property_tree/detail/json_parser_read.hpp:105:17: error: no matching function for call to ‘boost::property_tree::basic_ptree<std::basic_string<char>, std::basic_string<char> >::push_back(std::pair<std::basic_string<char>, std::basic_string<char> >)’
/usr/include/boost/property_tree/detail/json_parser_read.hpp:105:17: note: candidate is:
In file included from /usr/include/boost/property_tree/ptree.hpp:516:0,
from test.cpp:3:
/usr/include/boost/property_tree/detail/ptree_implementation.hpp:362:9: note: boost::property_tree::basic_ptree<Key, Data, KeyCompare>::iterator boost::property_tree::basic_ptree<Key, Data, KeyCompare>::push_back(const value_type&) [with Key = std::basic_string<char>; Data = std::basic_string<char>; KeyCompare = std::less<std::basic_string<char> >; boost::property_tree::basic_ptree<Key, Data, KeyCompare>::value_type = std::pair<const std::basic_string<char>, boost::property_tree::basic_ptree<std::basic_string<char>, std::basic_string<char> > >]
/usr/include/boost/property_tree/detail/ptree_implementation.hpp:362:9: note: no known conversion for argument 1 from ‘std::pair<std::basic_string<char>, std::basic_string<char> >’ to ‘const value_type& {aka const std::pair<const std::basic_string<char>, boost::property_tree::basic_ptree<std::basic_string<char>, std::basic_string<char> > >&}’
最佳答案
这是一个 known bug较旧的 Boost 版本。
您可以通过应用以下补丁来修复它:
--- json_parser_read.hpp 2013-09-01 03:55:57.000000000 +0400
+++ /usr/include/boost/property_tree/detail/json_parser_read.hpp 2013-09-01 03:56:21.000000000 +0400
@@ -102,7 +102,7 @@
void operator()(It b, It e) const
{
BOOST_ASSERT(c.stack.size() >= 1);
- c.stack.back()->push_back(std::make_pair(c.name, Str(b, e)));
+ c.stack.back()->push_back(std::make_pair(c.name, Ptree(Str(b, e))));
c.name.clear();
c.string.clear();
}
sed -i -e 's/std::make_pair(c.name, Str(b, e))/std::make_pair(c.name, Ptree(Str(b, e)))/' json_parser_read.hpp
关于json - 提升 read_json 和 C++11,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18552427/
我正在尝试将 json 文件加载到 dask df 中。 files = glob.glob('**/*.json', recursive=True) df = dd.read_json(files,
我在 a.json 文件中有以下数据。 { "1000000000": { "TEST": 2 } } import pandas as pd df = pd.read_json(r"
我有一个用 pd.read_json() 创建的 Pandas 数据框。当我读入它时,我得到一些只有空列表或无的单元格,我想检测某些列中带有 [], None 的行。例如: feat 1
我编写了一个 python 脚本,该脚本应该通过读取 json 文件来形成 csv。 json文件实际上是一行json,即每一行代表一个json对象。在我的 json 文件中,每一行都有一个键和一个值
在执行以下操作时,我不断收到“打开的文件过多”错误: # read file names file_names = [] for file_name in os.listdir(path):
我正在尝试将以下 JSON 读入 DataFrame: [{"col1": 900000000000000000000}] 当我运行 pd.read_json('sample.json') 时收到错误
我正在使用 Pandas 从 API 获取数据。 API 返回 JSON 格式的数据。但是,json 在数据框中有一些我不想要的值。由于这些值,我无法为数据框分配索引。以下是格式。 { "Succes
我正在尝试读取存储为 json 文件的推文。我正在使用 pandas 来加载数据。但在 read_json 函数中发现了一些奇怪的行为。我提供一个 mcve如下: json_content=""" {
我有一个看起来像这样的 json 文件: [{"A": 0, "B": "x"}, {"A": 1, "B": "y", "C": 0}, {"A": 2, "B": "z", "C": 1}] 由于
我正在尝试读取和处理一个大的 json 文件(~16G),但即使我通过指定 chunksize=500 读取小块,它仍然有内存错误。我的代码: i=0 header = True for chunk
我不是一个夸张的人,但我真的被这个错误难住了,我相信你也会被难住...... 这是一个简单的 json 对象: [ { "id": "7012104767417052471",
我们在不同的进程中使用 read_json(),我们遇到了崩溃。 #0 0x00007f062ce0d094 in std::mem_fun1_t > >, boost::spirit::c
我无法用 boost::property_tree::read_json 解决我的问题。我有带有 MBCS 编码(多字节字符集)的 MFC 项目。我在读取带有 ä 字符的数据时出错。这是我的例子: n
我以前从未使用过 json 文件。目前这就是我正在做的: df = pd.read_json("precincts-with-results.geojson.gz") df['features'] 这
我正在尝试使用 Boost 的 property_tree 解析器和 C++11 代码来解析 JSON(我的系统是带有 gcc 4.7.2 和 Boost 1.49 的 Debian Wheezy)。
我制作了一个 250MB 的 json 文件,它应该是这样的: [ {"A":"uniquevalue0", "B":[1,2,3]}, {"A":"uniquevalue1", "B":[1]}
我非常快速地进行了测试,看看是否可以将我的 Twitter 提要通过管道传输到 boost 的 JSON 解析器。没有骰子。我的 JSON 解析器无法处理以下行: "profile_backgroun
设置 这个问题的基础是我正在使用 celery和 rabbitmq创建一个分布式 HDFStore 消息传递应用程序,该应用程序将把 pandas DataFrame 传递给分布式进程(然后写入 HD
我使用 to_json 方法来序列化我的数据帧,内容如下所示: "1467065160244362165":"1985.875","1467065161029130301":"1985.875","1
我使用 Boost Asio (1.53.0) 制作了一个简单的 TCP 服务器。服务器接受 JSON 请求,使用 boost::property_tree::read_json 解析它们。 为了测试
我是一名优秀的程序员,十分优秀!