• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

cierelabs/json_spirit: C++ JSON Library including both a json-data-structure and ...

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称:

cierelabs/json_spirit

开源软件地址:

https://github.com/cierelabs/json_spirit

开源编程语言:

C++ 92.5%

开源软件介绍:

json spirit

A json library using Boost.Spirit V2 and X3 for the parser.

The primary goal of the json spirit library was to create a conformant json parser that resulted in a json object that could be manipulated much like in javascript or python.

Quick Example

// the json::value is the primary data type
// you can simply assign it values

json::value v = 42;
v = "foo";
v = true;
v = 14.5;

// you can also treat the json::value like an array
v[0] = "foo";
v[1] = true;

// or a json object
v["foo"] = 42;
v["bar"] = false;

// and of course, these can be more complex
json::value z;
z[4] = v;

std::cout << z << "\n";

which would result in:

[null, null, null, null, {"bar":false, "foo":42}]

Building

We have CMake and Boost.Build support.

CMake

For CMake, do this to build the library:

cd json_spirit
mkdir build
cd build
cmake ..
make

You may specify the version of Boost to build against by defining BOOST_ROOT on the CMake command line like this:

cmake -DBOOST_ROOT=/sandbox/boost/trunk ..

To run the unit tests:

make test

Using in another CMakeLists.txt

One way to use the json library in another CMake project is to treat it as an external project.

Here is an example of how to do that:

  # Find json spirit
  ExternalProject_Add(
    dependency.json_spirit
    URL ${CMAKE_CURRENT_SOURCE_DIR}/vendor/json_spirit
    PREFIX ${CMAKE_CURRENT_BINARY_DIR}/json_spirit
    CMAKE_COMMAND ${CMAKE_COMMAND}
    CMAKE_GENERATOR ${CMAKE_GENERATOR}
    CMAKE_ARGS ${BOOST_CMAKE_ARGS} -DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE}
    BUILD_COMMAND ${CMAKE_COMMAND} --build <BINARY_DIR> --config $<CONFIG> --target json
    INSTALL_COMMAND "")
  
  ExternalProject_Get_Property(dependency.json_spirit SOURCE_DIR BINARY_DIR)
  set(INSTALL_DIR ${BINARY_DIR}/${CMAKE_CFG_INTDIR})
  
  add_library(json_spirit STATIC IMPORTED)
  
  set(libjson_name "${CMAKE_STATIC_LIBRARY_PREFIX}json${CMAKE_STATIC_LIBRARY_SUFFIX}")
  set_property(
    TARGET json_spirit
    PROPERTY IMPORTED_LOCATION ${INSTALL_DIR}/${libjson_name})
  
  set_property(
    TARGET json_spirit
    PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${SOURCE_DIR})
  
  add_dependencies(json_spirit dependency.json_spirit)

and for your specific target you can:

    target_link_libraries(my_target
                          json_spirit
                          .... other libraries ... )

Boost.Build

For Boost.Build, we assume either your user-config.jam file has a line like this:

use-project /boost	:	/sandbox/boost/trunk ;

or you have set the environment variable BOOST_ROOT to the location of the boost version you want to use.

You can build the library via:

cd json_spirit
bjam json

You can build the tests via:

cd json_spirit/libs/json/test
bjam

Bazel Build

For bazel depending on this library using the bazel build system add the following to your WORKSPACE file

load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository")

git_repository(
  name = "com_github_cierelabs_json_spirit",
  remote = "https://github.com/cierelabs/json_spirit",
  commit = "371c3b5d283f6272860d4d2eac996591ffad259c"
)

load("@com_github_cierelabs_json_spirit//:json_spirit_deps.bzl", "json_spirit_deps")

json_spirit_deps()

load("@com_github_nelhage_rules_boost//:boost/boost.bzl", "boost_deps")

boost_deps()

The library can now be depended on using the target @com_github_cierelabs_json_spirit:json_spirit e.g.

cc_library(
  name = "some_lib",
  deps = ["@com_github_cierelabs_json_spirit:json_spirit"],
  # ...
)

Documentation

Coming soon. Unit tests located in libs/json/test/*.cpp provide a good starting point for exploration of the functionality.

Licensing

json_spirit is licensed under the Boost Software License. See LICENSE_1_0.txt for details.




鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
liruqi/jsonviewer: online json viewer发布时间:2022-07-09
下一篇:
learn-co-students/diy-json-serializer-lab-v-000发布时间:2022-07-09
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap