STTNet
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Static Public Member Functions | List of all members
stt::data::JsonHelper Class Reference

class of solving json data More...

#include <sttnet_English.h>

Static Public Member Functions

static int getValue (const std::string &oriStr, std::string &result, const std::string &type="value", const std::string &name="a", const int &num=0)
 Extract the value or nested structure of a specified field in a JSON string. More...
 
static std::string toString (const Json::Value &val)
 Convert Json::Value to a string. More...
 
static Json::Value toJsonArray (const std::string &str)
 Parse a JSON string into Json::Value. More...
 
template<class T1 , class T2 >
static std::string createJson (T1 first, T2 second)
 Create a JSON string containing only one key-value pair. More...
 
template<class T1 , class T2 , class... Args>
static std::string createJson (T1 first, T2 second, Args...args)
 Create a JSON string composed of multiple key-value pairs (recursive variadic template). More...
 
template<class T >
static std::string createArray (T first)
 Create a JSON array string containing only one element. More...
 
template<class T , class... Args>
static std::string createArray (T first, Args...args)
 Create a JSON array string composed of multiple elements (recursive variadic template). More...
 
static std::string jsonAdd (const std::string &a, const std::string &b)
 Concatenate two JSON strings into a valid JSON (suitable for object or array concatenation). More...
 
static std::string & jsonFormatify (const std::string &a, std::string &b)
 Remove indentation, spaces, etc., from a formatted JSON string to make it compact. More...
 
static std::string & jsonToUTF8 (const std::string &input, std::string &output)
 Convert in a JSON string to UTF-8 characters. More...
 

Detailed Description

class of solving json data

Member Function Documentation

template<class T >
static std::string stt::data::JsonHelper::createArray ( first)
inlinestatic

Create a JSON array string containing only one element.

Parameters
TAny type.
firstThe first element.
Returns
std::string JSON array string.
template<class T , class... Args>
static std::string stt::data::JsonHelper::createArray ( first,
Args...  args 
)
inlinestatic

Create a JSON array string composed of multiple elements (recursive variadic template).

Parameters
TType of the first element.
ArgsTypes of the remaining elements.
firstThe first element.
argsThe remaining elements.
Returns
std::string The concatenated JSON array string.
template<class T1 , class T2 >
static std::string stt::data::JsonHelper::createJson ( T1  first,
T2  second 
)
inlinestatic

Create a JSON string containing only one key-value pair.

Parameters
T1Type of the key, usually std::string.
T2Type of the value, can be any type acceptable to Json::Value.
firstKey.
secondValue.
Returns
std::string JSON string.
template<class T1 , class T2 , class... Args>
static std::string stt::data::JsonHelper::createJson ( T1  first,
T2  second,
Args...  args 
)
inlinestatic

Create a JSON string composed of multiple key-value pairs (recursive variadic template).

Parameters
T1Type of the first key.
T2Type of the first value.
ArgsThe remaining key-value parameters in pairs.
firstThe first key.
secondThe first value.
argsThe remaining key-value parameters.
Returns
std::string The concatenated JSON string.
static int stt::data::JsonHelper::getValue ( const std::string &  oriStr,
std::string &  result,
const std::string &  type = "value",
const std::string &  name = "a",
const int &  num = 0 
)
static

Extract the value or nested structure of a specified field in a JSON string.

Parameters
oriStrraw JSON string.
resultstores a string reference to the return value.
typemode, optional values: value, arrayvalue. They are the values in ordinary JSON objects and the values in array objects.
namekey name in JSON (value only).
numarray index position (starting from 0) (for arrayvalue only).
Returns
-1: Extraction failed 0: Returns a non-JSON object 1: Returns a JSON object
static std::string stt::data::JsonHelper::jsonAdd ( const std::string &  a,
const std::string &  b 
)
static

Concatenate two JSON strings into a valid JSON (suitable for object or array concatenation).

Parameters
aThe first JSON string.
bThe second JSON string.
Returns
std::string Concatenated JSON string.
static std::string& stt::data::JsonHelper::jsonFormatify ( const std::string &  a,
std::string &  b 
)
static

Remove indentation, spaces, etc., from a formatted JSON string to make it compact.

Parameters
aInput JSON string.
bReference to store the formatted result.
Returns
std::string& Reference to the compact format string.
static std::string& stt::data::JsonHelper::jsonToUTF8 ( const std::string &  input,
std::string &  output 
)
static

Convert in a JSON string to UTF-8 characters.

Parameters
inputJSON string with Unicode encoding.
outputReference to store the converted string.
Returns
std::string& Reference to the converted string.
static Json::Value stt::data::JsonHelper::toJsonArray ( const std::string &  str)
static

Parse a JSON string into Json::Value.

Parameters
strInput JSON string.
Returns
Json::Value Parsed JSON object or array.
static std::string stt::data::JsonHelper::toString ( const Json::Value &  val)
static

Convert Json::Value to a string.

Parameters
valJSON value.
Returns
std::string String form of the value.

The documentation for this class was generated from the following file: