Skip to content

Commit 384026e

Browse files
committed
added working example
1 parent 2baad49 commit 384026e

File tree

6 files changed

+157
-9
lines changed

6 files changed

+157
-9
lines changed

example/jsontest/CMakeLists.txt

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
cmake_minimum_required(VERSION 2.8.3)
2+
project(jsontest)
3+
4+
add_compile_options(-std=c++11)
5+
6+
find_package(catkin REQUIRED COMPONENTS)
7+
8+
find_package(jsoncpp REQUIRED)
9+
10+
catkin_package(
11+
INCLUDE_DIRS include
12+
LIBRARIES
13+
CATKIN_DEPENDS
14+
DEPENDS jsoncpp
15+
)
16+
17+
include_directories(
18+
include
19+
${catkin_INCLUDE_DIRS}
20+
)
21+
22+
add_executable(${PROJECT_NAME}_node src/jsontest_node.cpp)
23+
24+
target_link_libraries(${PROJECT_NAME}_node
25+
${catkin_LIBRARIES}
26+
jsoncpp
27+
)
28+

example/jsontest/package.xml

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
<?xml version="1.0"?>
2+
<package format="2">
3+
<name>jsontest</name>
4+
<version>0.0.0</version>
5+
<description>The jsontest package</description>
6+
7+
<!-- One maintainer tag required, multiple allowed, one person per tag -->
8+
<!-- Example: -->
9+
<!-- <maintainer email="[email protected]">Jane Doe</maintainer> -->
10+
<maintainer email="[email protected]">cn</maintainer>
11+
12+
13+
<!-- One license tag required, multiple allowed, one license per tag -->
14+
<!-- Commonly used license strings: -->
15+
<!-- BSD, MIT, Boost Software License, GPLv2, GPLv3, LGPLv2.1, LGPLv3 -->
16+
<license>TODO</license>
17+
18+
19+
<!-- Url tags are optional, but multiple are allowed, one per tag -->
20+
<!-- Optional attribute type can be: website, bugtracker, or repository -->
21+
<!-- Example: -->
22+
<!-- <url type="website">http://wiki.ros.org/jsontest</url> -->
23+
24+
25+
<!-- Author tags are optional, multiple are allowed, one per tag -->
26+
<!-- Authors do not have to be maintainers, but could be -->
27+
<!-- Example: -->
28+
<!-- <author email="[email protected]">Jane Doe</author> -->
29+
30+
31+
<!-- The *depend tags are used to specify dependencies -->
32+
<!-- Dependencies can be catkin packages or system dependencies -->
33+
<!-- Examples: -->
34+
<!-- Use depend as a shortcut for packages that are both build and exec dependencies -->
35+
<!-- <depend>roscpp</depend> -->
36+
<!-- Note that this is equivalent to the following: -->
37+
<!-- <build_depend>roscpp</build_depend> -->
38+
<!-- <exec_depend>roscpp</exec_depend> -->
39+
<!-- Use build_depend for packages you need at compile time: -->
40+
<!-- <build_depend>message_generation</build_depend> -->
41+
<!-- Use build_export_depend for packages you need in order to build against this package: -->
42+
<!-- <build_export_depend>message_generation</build_export_depend> -->
43+
<!-- Use buildtool_depend for build tool packages: -->
44+
<!-- <buildtool_depend>catkin</buildtool_depend> -->
45+
<!-- Use exec_depend for packages you need at runtime: -->
46+
<!-- <exec_depend>message_runtime</exec_depend> -->
47+
<!-- Use test_depend for packages you need only for testing: -->
48+
<!-- <test_depend>gtest</test_depend> -->
49+
<!-- Use doc_depend for packages you need only for building documentation: -->
50+
<!-- <doc_depend>doxygen</doc_depend> -->
51+
<buildtool_depend>catkin</buildtool_depend>
52+
<build_depend>jsoncpp</build_depend>
53+
<build_export_depend>jsoncpp</build_export_depend>
54+
<exec_depend>jsoncpp</exec_depend>
55+
56+
57+
<!-- The export tag contains other, unspecified, tags -->
58+
<export>
59+
<!-- Other tools can request additional information be placed here -->
60+
61+
</export>
62+
</package>
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#include <iostream>
2+
#include <json/json.h>
3+
4+
int main( int argc, const char* argv[] )
5+
{
6+
Json::Value root; // 'root' will contain the root value after parsing.
7+
std::cin >> root;
8+
// You can also read into a particular sub-value.
9+
std::cin >> root["subtree"];
10+
// Get the value of the member of root named 'encoding',
11+
// and return 'UTF-8' if there is no such member.
12+
std::string encoding = root.get("encoding", "UTF-8" ).asString();
13+
// Get the value of the member of root named 'plug-ins'; return a 'null' value if
14+
// there is no such member.
15+
const Json::Value plugins = root["plug-ins"];
16+
// Iterate over the sequence elements.
17+
for ( int index = 0; index < plugins.size(); ++index )
18+
loadPlugIn( plugins[index].asString() );
19+
20+
// Try other datatypes. Some are auto-convertible to others.
21+
foo::setIndentLength( root["indent"].get("length", 3).asInt() );
22+
foo::setIndentUseSpace( root["indent"].get("use_space", true).asBool() );
23+
// Since Json::Value has an implicit constructor for all value types, it is not
24+
// necessary to explicitly construct the Json::Value object.
25+
root["encoding"] = foo::getCurrentEncoding();
26+
root["indent"]["length"] = foo::getCurrentIndentLength();
27+
root["indent"]["use_space"] = foo::getCurrentIndentUseSpace();
28+
// If you like the defaults, you can insert directly into a stream.
29+
std::cout << root;
30+
// Of course, you can write to `std::ostringstream` if you prefer.
31+
// If desired, remember to add a linefeed and flush.
32+
std::cout << std::endl;
33+
return 0;
34+
}

example/jsontest/src/test.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"stocks": [
3+
{"symbol": "AAPL",
4+
"amount": 1.03213,
5+
"last_price": 1.20},
6+
{"symbol": "MSFT",
7+
"amount": 2.31039},
8+
{"symbol": "F",
9+
"amount": 0.543589}
10+
]
11+
}

include/json/version.h

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
11
// DO NOT EDIT. This file (and "version") is generated by CMake.
22
// Run CMake configure step to update it.
33
#ifndef JSON_VERSION_H_INCLUDED
4-
#define JSON_VERSION_H_INCLUDED
4+
# define JSON_VERSION_H_INCLUDED
55

6-
#define JSONCPP_VERSION_STRING "1.8.4"
7-
#define JSONCPP_VERSION_MAJOR 1
8-
#define JSONCPP_VERSION_MINOR 8
9-
#define JSONCPP_VERSION_PATCH 4
10-
#define JSONCPP_VERSION_QUALIFIER
11-
#define JSONCPP_VERSION_HEXA \
12-
((JSONCPP_VERSION_MAJOR << 24) | (JSONCPP_VERSION_MINOR << 16) | \
13-
(JSONCPP_VERSION_PATCH << 8))
6+
# define JSONCPP_VERSION_STRING "1.8.4"
7+
# define JSONCPP_VERSION_MAJOR 1
8+
# define JSONCPP_VERSION_MINOR 8
9+
# define JSONCPP_VERSION_PATCH 4
10+
# define JSONCPP_VERSION_QUALIFIER
11+
# define JSONCPP_VERSION_HEXA ((JSONCPP_VERSION_MAJOR << 24) | (JSONCPP_VERSION_MINOR << 16) | (JSONCPP_VERSION_PATCH << 8))
1412

1513
#ifdef JSONCPP_USING_SECURE_MEMORY
1614
#undef JSONCPP_USING_SECURE_MEMORY

install_manifest.txt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/usr/local/lib/pkgconfig/jsoncpp.pc
2+
/usr/local/lib/cmake/jsoncpp/jsoncppConfig.cmake
3+
/usr/local/lib/cmake/jsoncpp/jsoncppConfig-release.cmake
4+
/usr/local/lib/libjsoncpp.a
5+
/usr/local/include/json/allocator.h
6+
/usr/local/include/json/assertions.h
7+
/usr/local/include/json/autolink.h
8+
/usr/local/include/json/config.h
9+
/usr/local/include/json/features.h
10+
/usr/local/include/json/forwards.h
11+
/usr/local/include/json/json.h
12+
/usr/local/include/json/reader.h
13+
/usr/local/include/json/value.h
14+
/usr/local/include/json/version.h
15+
/usr/local/include/json/writer.h

0 commit comments

Comments
 (0)