Cuberite
A lightweight, fast and extensible game server for Minecraft
JsonUtils.cpp
Go to the documentation of this file.
1 #include "Globals.h"
2 
3 #include "JsonUtils.h"
4 #include "json/json.h"
5 
6 #include <sstream>
7 
8 
9 namespace JsonUtils
10 {
11 
12 AString WriteFastString(const Json::Value & a_Root)
13 {
14  Json::StreamWriterBuilder Builder;
15  Builder["commentStyle"] = "None";
16  Builder["indentation"] = "";
17  return Json::writeString(Builder, a_Root);
18 }
19 
20 
21 
22 
23 
24 AString WriteStyledString(const Json::Value & a_Root)
25 {
26  Json::StreamWriterBuilder Builder;
27  return Json::writeString(Builder, a_Root);
28 }
29 
30 
31 
32 
33 
34 bool ParseString(const AString & a_JsonStr, Json::Value & a_Root, AString * a_ErrorMsg)
35 {
36  Json::CharReaderBuilder Builder;
37  std::unique_ptr<Json::CharReader> Reader(Builder.newCharReader());
38 
39  const char * Doc = a_JsonStr.data();
40  return Reader->parse(Doc, Doc + a_JsonStr.size(), &a_Root, a_ErrorMsg);
41 }
42 
43 
44 
45 
46 
48  const AString & a_Key, const AString & a_Value)
49 {
50  Json::Value root;
51  root[a_Key] = a_Value;
52  return JsonUtils::WriteFastString(root);
53 }
54 
55 } // namespace JsonUtils
std::string AString
Definition: StringUtils.h:11
AString SerializeSingleValueJsonObject(const AString &a_Key, const AString &a_Value)
Creates a Json string representing an object with the specified single value.
Definition: JsonUtils.cpp:47
AString WriteStyledString(const Json::Value &a_Root)
Definition: JsonUtils.cpp:24
AString WriteFastString(const Json::Value &a_Root)
Definition: JsonUtils.cpp:12
bool ParseString(const AString &a_JsonStr, Json::Value &a_Root, AString *a_ErrorMsg)
Definition: JsonUtils.cpp:34