本文整理汇总了C++中json::Object类的典型用法代码示例。如果您正苦于以下问题:C++ Object类的具体用法?C++ Object怎么用?C++ Object使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Object类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: printHomeData
void printHomeData(ULONG ID) {
printHeaders();
JSON::Object obj;
obj.add(new JSON::String("ID"), new JSON::Integer(ID));
obj.add(new JSON::String("homeData"), new JSON::String("test"));
obj.render();
}
示例2: isActive
// Test connection with node.
bool ElasticSearch::isActive() {
Json::Object root;
try {
_http.get(0, 0, &root);
}
catch(Exception& e){
printf("get(0) failed in ElasticSearch::isActive(). Exception caught: %s\n", e.what());
return false;
}
catch(std::exception& e){
printf("get(0) failed in ElasticSearch::isActive(). std::exception caught: %s\n", e.what());
return false;
}
catch(...){
printf("get(0) failed in ElasticSearch::isActive().\n");
return false;
}
if(root.empty())
return false;
if(!root.member("status") || root["status"].getInt() != 200){
printf("Status is not 200. Cannot find Elasticsearch Node.\n");
return false;
}
return true;
}
示例3:
Promise<void> Client::ClientSession (
String access_token,
String profile_id,
String server_id,
const Vector<Byte> & secret,
const Vector<Byte> & public_key
) {
// Create JSON request
JSON::Object obj;
obj.Add(
session_token_key,
std::move(access_token),
session_profile_key,
std::move(profile_id),
session_server_id_key,
get_hash(server_id,secret,public_key)
);
// We have to use a custom URL
auto request=get_request(std::move(obj));
request.URL=String::Format(
session_url,
client_session_endpoint
);
// Dispatch
return dispatch<void>(std::move(request));
}
示例4: create
SEXP create(const json::Object& value, Protect* pProtect)
{
// create the list
SEXP listSEXP ;
pProtect->add(listSEXP = Rf_allocVector(VECSXP, value.size()));
// build list of names
SEXP namesSEXP ;
pProtect->add(namesSEXP = Rf_allocVector(STRSXP, value.size()));
// add each object field to it
int index = 0;
for (json::Object::const_iterator
it = value.begin();
it != value.end();
++it)
{
// set name
SET_STRING_ELT(namesSEXP, index, Rf_mkChar(it->first.c_str()));
// set value
SEXP valueSEXP = create(it->second, pProtect);
SET_VECTOR_ELT(listSEXP, index, valueSEXP);
// increment element index
index++;
}
// attach names
Rf_setAttrib(listSEXP, R_NamesSymbol, namesSEXP);
// return the list
return listSEXP;
}
示例5: ParseRenderTargets
void CompositorLoader::ParseRenderTargets(Compositor::Ptr& compositor, const json::Object& renderTargets)
{
for (auto it = renderTargets.begin(); it != renderTargets.end(); ++it)
{
const Value& data = it->second;
DataFormat dataFormat = JsonTypeHelper::ParseDataFormat(data);
compositor->AddRenderTarget(it->first, dataFormat);
if (data.HasKey("scale"))
{
compositor->SetRenderTargetScale(it->first, JsonTypeHelper::ParseFloatVector(data["scale"]).XY());
}
if (dataFormat.IsDepthFormat())
{
if (data.HasKey("clearDepth"))
{
compositor->SetClearDepth(it->first, data["clearDepth"].ToFloat(1.0f));
}
}
else
{
if (data.HasKey("clearColor"))
{
compositor->SetClearColor(it->first, JsonTypeHelper::ParseColor(data["clearColor"]));
}
}
}
}
示例6: index
/// Index a document.
bool ElasticSearch::index(const std::string& index, const std::string& type, const std::string& id, const Json::Object& jData){
if(_readOnly)
return false;
std::stringstream url;
url << index << "/" << type << "/" << id;
std::stringstream data;
data << jData;
Json::Object result;
_http.put(url.str().c_str(), data.str().c_str(), &result);
if(!result.member("created"))
EXCEPTION("The index induces error.");
if(result.getValue("created"))
return true;
std::cout << "endPoint: " << index << "/" << type << "/" << id << std::endl;
std::cout << "jData" << jData.pretty() << std::endl;
std::cout << "result" << result.pretty() << std::endl;
EXCEPTION("The index returns ok: false.");
return false;
}
示例7: update_doc
void BulkBuilder::update_doc(const std::string &index, const std::string &type, const std::string &id, const Json::Object &fields, bool upsert) {
createCommand("update", index, type, id);
Json::Object updateFields;
updateFields.addMemberByKey("doc", fields);
updateFields.addMemberByKey("doc_as_upsert", upsert);
operations.push_back(updateFields);
}
示例8:
WeatherForecast::WeatherForecast(const Json::Object &json)
: _city(json.get("city"))
{
_count = json.get("cnt").toNumber().orIfNull(0);
_cod = json.get("cod").toString().orIfNull("");
Json::Array weathers = json.get("list");
for(auto w: weathers) {
_weathers.push_back({w});
}
}
示例9: deleteDocument
/// Delete the document by index/type/id.
bool ElasticSearch::deleteDocument(const char* index, const char* type, const char* id){
if(_readOnly)
return false;
std::ostringstream oss;
oss << index << "/" << type << "/" << id;
Json::Object msg;
_http.remove(oss.str().c_str(), 0, &msg);
return msg.getValue("found");
}
示例10: ToJSON
JSON::Object Profile::ToJSON () {
JSON::Object retr;
retr.Add(
profile_id_key,
std::move(ID),
profile_name_key,
std::move(Name)
);
return retr;
}
示例11: printf
// Request the document number of type T in index I.
long unsigned int ElasticSearch::getDocumentCount(const char* index, const char* type){
std::ostringstream oss;
oss << index << "/" << type << "/_count";
Json::Object msg;
_http.get(oss.str().c_str(),0,&msg);
size_t pos = 0;
if(msg.member("count"))
pos = msg.getValue("count").getUnsignedInt();
else
printf("We did not find \"count\" member.\n");
return pos;
}
示例12: exceptionIfMissingKeys
void exceptionIfMissingKeys(
const json::Object& obj,
const string& objKey,
const string& key) {
if (!obj.HasKey(objKey)) {
throw VrCamException("JSON error. missing key:" + objKey);
}
const json::Object obj2 = obj[objKey];
if (!obj2.HasKey(key)) {
throw VrCamException("JSON error. missing key:" + key);
}
}
示例13: exist
// Test if document exists
bool ElasticSearch::exist(const std::string& index, const std::string& type, const std::string& id){
std::stringstream url;
url << index << "/" << type << "/" << id;
Json::Object result;
_http.get(url.str().c_str(), 0, &result);
if(!result.member("found")){
std::cout << result << std::endl;
EXCEPTION("Database exception, field \"found\" must exist.");
}
return result.getValue("found");
}
示例14: readObject
core::Error readObject(const json::Object& object,
const std::string& name,
T* pValue)
{
json::Object::const_iterator it = object.find(name) ;
if (it == object.end())
return Error(errc::ParamMissing, ERROR_LOCATION) ;
if (!isType<T>(it->second))
return Error(errc::ParamTypeMismatch, ERROR_LOCATION) ;
*pValue = it->second.get_value<T>() ;
return Success() ;
}
示例15: deleteAll
/// Delete the document by index/type.
bool ElasticSearch::deleteAll(const char* index, const char* type){
if(_readOnly)
return false;
std::ostringstream uri, data;
uri << index << "/" << type << "/_query";
data << "{\"query\":{\"match_all\": {}}}";
Json::Object msg;
_http.remove(uri.str().c_str(), data.str().c_str(), &msg);
if(!msg.member("_indices") || !msg["_indices"].getObject().member(index) || !msg["_indices"].getObject()[index].getObject().member("_shards"))
return false;
if(!msg["_indices"].getObject()[index].getObject()["_shards"].getObject().member("failed"))
return false;
return (msg["_indices"].getObject()[index].getObject()["_shards"].getObject()["failed"].getInt() == 0);
}