Boost属性树是否具有用于定义要解析的数据的规则的方法? [英] Does Boost Property Tree have methods for defining rules for the data to be parsed?

查看:143
本文介绍了Boost属性树是否具有用于定义要解析的数据的规则的方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个项目,该项目将使用单个JSON文件来描述其中包含的目录的内部内容. Boost属性树库似乎是JSON解析库的最佳选择.但是,这个JSON文件(与其他文件一样)应该具有非常特殊的布局,到目前为止,我还没有找到一种在代码中表达规则的好方法.

I have a project that will be using a single JSON file in order to describe the inner contents of the directory it is contained within. The Boost Property Tree library appears to be the best choice for a JSON parsing library. However, this JSON file (like many others) is expected to have a very particular layout, and so far I haven't found a good manner of expressing the rules in code.

Boost属性树库是否具有允许用户执行以下任何操作的任何方法?

Does the Boost Property Tree library have any methods allowing the user to do any of the following?

  • 禁止使用无法识别的键.
  • 根据需要或可选指定密钥.
  • 指定键的期望值类型(null,bool,int,float,array,dictionary).

到目前为止,我已经找到了这个先前的问题,它发出了一些光芒有关如何将一些JSON键值对转换为数据结构的信息,但是它无法回答上面列出的任何功能是否可能.

So far I've found this previous question which shines some light on how to translate some JSON key-value pairs into data structures, but it doesn't answer whether any of the capabilities listed above are possible.

推荐答案

由于缺乏类型,属性树没多久就让我放弃(正如sehe指出的).

Property Tree didn't take long for me to give up on due to lack of types (as sehe pointed out).

为了进一步完善这些建议,如果您正在处理JSON,我会推荐一个易于使用的库,例如 nlohmann's库.这是相当快速和直观的.

To take sehe's recommendation further, if you are dealing with JSON, I would recommend a user-friendly library like nlohmann's library instead. It is reasonably fast and intuitive.

还有RapidJSON,它困扰着内存分配的每一点,等等,影响了可用性,但在(自己的)测试.在转向nlohmann之前,我在处理单项数组时遇到了困难.

There is also RapidJSON, which obsesses over every bit of memory allocation, etc, impacting usability, but the best performer in (its own) tests. I encountered difficulty with its handling of single-item arrays before moving to nlohmann's.

这篇关于Boost属性树是否具有用于定义要解析的数据的规则的方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆