如果不是json但与之相似,如何使用boost进行解析? [英] How to parse using boost if it is not json, but similar to it?

查看:112
本文介绍了如果不是json但与之相似,如何使用boost进行解析?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个应用程序,它从json文件中读取一些参数,但是现在文件已更改(这不是我的决定).该文件看起来几乎相同,但是它不是{},而是[],因此,如果到目前为止,它看起来像是

I have an application that reads some parameters from a json file, but now the file has changed (it is not my decision). The file looks pretty the same, but instead of {} it has [], so if until now it looked like

{
  "A":
  {
    "a":"a",
    "b":"b"
  }
}

现在是这样的:

[
  "A":
  [
    "a":"a",
    "b":"b"
  ]
]

我的应用程序是用C ++编写的,所以我使用boost来解析json文件,但是现在我正在寻找一个新的解析器,有没有办法使用boost来实现呢?

My application is written in C++, so I have used boost to parse the json file, but now I am looking for a new parser, is there a way to do it with boost?

我已经开始搜索,但是我也问了一个问题,认为也许有人可以比我更快地找到答案.谢谢

I have started to search, but I have also asked the question thinking that maybe someone may help me faster than me finding the answer. Thanks

推荐答案

它看起来像是另一个YAML/Mustache/JSON/...派生类.

It looks like Yet Another YAML/Mustache/JSON/... derivative.

没有正式的规范,很难真正评估所需的工作量,但这是Boost Spirit中类似语法的实现列表,并且具有不同的功能完整性:

Without a formal spec it's hard to actually assess what effort would be required, but here's a list of implementations of similar grammars in Boost Spirit, with varying amounts of feature completeness:

  • How to parse mustache with Boost.Xpressive correctly? <-- this is likely your best matching demonstration
  • Parse a substring as JSON using QJsonDocument (minimal subset, use something like this to transform the input to proper JSON, e.g.?)
  • Reading JSON file with C++ and BOOST A full featured JSON parser (with AST and escapes but no comments)

玩具JSON解析器实现的应用程序:

Applications of a toy JSON parser implementation:

  • replace only some value from json to json
  • How to manipulate leaves of a JSON tree
  • more

这篇关于如果不是json但与之相似,如何使用boost进行解析?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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