本文整理汇总了C++中json::Object类的典型用法代码示例。如果您正苦于以下问题:C++ Object类的具体用法?C++ Object怎么用?C++ Object使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Object类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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();
}
开发者ID:justwalk,项目名称:Panasonic,代码行数:7,代码来源:output.cpp
示例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;
}
开发者ID:WillBrennan,项目名称:cpp-elasticsearch,代码行数:31,代码来源:elasticsearch.cpp
示例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));
}
开发者ID:andrewphorn,项目名称:MCPP,代码行数:30,代码来源:yggdrasil.cpp
示例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;
}
开发者ID:dreammaster38,项目名称:rstudio,代码行数:34,代码来源:RSexp.cpp
示例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"]));
}
}
}
}
开发者ID:lambertjamesd,项目名称:Krono,代码行数:30,代码来源:CompositorLoader.cpp
示例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;
}
开发者ID:WillBrennan,项目名称:cpp-elasticsearch,代码行数:28,代码来源:elasticsearch.cpp
示例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);
}
开发者ID:WillBrennan,项目名称:cpp-elasticsearch,代码行数:9,代码来源:elasticsearch.cpp
示例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});
}
}
开发者ID:GuLinux,项目名称:SkyPlanner,代码行数:10,代码来源:weatherforecast.cpp
示例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");
}
开发者ID:WillBrennan,项目名称:cpp-elasticsearch,代码行数:12,代码来源:elasticsearch.cpp
示例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;
}
开发者ID:andrewphorn,项目名称:MCPP,代码行数:13,代码来源:yggdrasil.cpp
示例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;
}
开发者ID:WillBrennan,项目名称:cpp-elasticsearch,代码行数:15,代码来源:elasticsearch.cpp
示例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);
}
}
开发者ID:AlexeyAB,项目名称:Surround360,代码行数:14,代码来源:JsonUtil.cpp
示例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");
}
开发者ID:WillBrennan,项目名称:cpp-elasticsearch,代码行数:15,代码来源:elasticsearch.cpp
示例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() ;
}
开发者ID:harupiko,项目名称:rstudio,代码行数:15,代码来源:JsonRpc.hpp
示例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);
}
开发者ID:WillBrennan,项目名称:cpp-elasticsearch,代码行数:19,代码来源:elasticsearch.cpp
示例16: update
// Update a document field.
bool ElasticSearch::update(const std::string& index, const std::string& type, const std::string& id, const std::string& key, const std::string& value){
if(_readOnly)
return false;
std::stringstream url;
url << index << "/" << type << "/" << id << "/_update";
std::stringstream data;
data << "{\"doc\":{\"" << key << "\":\""<< value << "\"}}";
Json::Object result;
_http.post(url.str().c_str(), data.str().c_str(), &result);
if(!result.member("_version"))
EXCEPTION("The update failed.");
return true;
}
开发者ID:WillBrennan,项目名称:cpp-elasticsearch,代码行数:19,代码来源:elasticsearch.cpp
示例17: search
/// Search API of ES.
long ElasticSearch::search(const std::string& index, const std::string& type, const std::string& query, Json::Object& result, const int n_result=10){
std::stringstream url;
url << index << "/" << type << "/_search?size=" << n_result;
_http.post(url.str().c_str(), query.c_str(), &result);
if(!result.member("timed_out")){
std::cout << url.str() << " -d " << query << std::endl;
std::cout << "result: " << result << std::endl;
EXCEPTION("Search failed.");
}
if(result.getValue("timed_out")){
std::cout << "result: " << result << std::endl;
EXCEPTION("Search timed out.");
}
return result.getValue("hits").getObject().getValue("total").getLong();
}
开发者ID:WillBrennan,项目名称:cpp-elasticsearch,代码行数:21,代码来源:elasticsearch.cpp
示例18: check
Promise<bool> Client::Validate (String access_token) {
// Create JSON request
JSON::Object obj;
obj.Add(
validate_token_key,
std::move(access_token)
);
// Dispatch request
return http.Execute(
get_request(
validate_endpoint,
std::move(obj)
)
).Then([] (Promise<MCPP::HTTPResponse> p) {
auto response=p.Get();
try {
check(response);
// We need to catch the ERROR to see whether
// it's JUST RETURNING FALSE ARE YOU KIDDING
// ME?
} catch (const Error & e) {
if (
(e.Type==invalid_token_type) &&
(e.Message==invalid_token_message)
) return false;
throw;
}
return true;
});
}
开发者ID:andrewphorn,项目名称:MCPP,代码行数:41,代码来源:yggdrasil.cpp
示例19: getMailSettings
void getMailSettings(JSON::Object &obj, IDatabase *db)
{
std::vector<std::wstring> slist=getMailSettingsList();
IQuery *q=db->Prepare("SELECT key, value FROM settings_db.settings WHERE clientid=0 AND key=?");
for(size_t i=0;i<slist.size();++i)
{
q->Bind(slist[i]);
db_results res=q->Read();
q->Reset();
if(!res.empty())
{
obj.set(Server->ConvertToUTF8(slist[i]), res[0][L"value"]);
}
else
{
std::string v="";
if(slist[i]==L"mail_serverport")
v="25";
obj.set(Server->ConvertToUTF8(slist[i]), v);
}
}
}
开发者ID:Averroes,项目名称:urbackup_backend,代码行数:22,代码来源:settings.cpp
示例20: fullScan
//retrive all documemnts of a class
int ElasticSearch::fullScan(const std::string& index, const std::string& type, const std::string& query, Json::Array& resultArray, int scrollSize) {
// Get the scroll id
std::stringstream scrollUrl;
scrollUrl << index << "/" << type << "/_search?search_type=scan&scroll=10m&size=" << scrollSize;
Json::Object scrollObject;
_http.post(scrollUrl.str().c_str(),query.c_str(),&scrollObject);
if(!scrollObject.member("hits"))
EXCEPTION("Result corrupted, no member \"hits\".");
if(!scrollObject.getValue("hits").getObject().member("total"))
EXCEPTION("Result corrupted, no member \"total\" nested in \"hits\".");
int total = scrollObject.getValue("hits").getObject().getValue("total").getInt();
std::string scrollId = scrollObject["_scroll_id"].getString();
int count = 0;
while(count < total) {
Json::Object result;
_http.rawpost("_search/scroll?scroll=10m", scrollId.c_str(), &result);
// Kepp the new scroll id we received to inject in the next iteration.
scrollId = result["_scroll_id"].getString();
for(const Json::Value& value : result["hits"].getObject()["hits"].getArray()){
resultArray.addElement(value);
++count;
}
}
if(count != total)
EXCEPTION("Result corrupted, total is different from count.");
return total;
}
开发者ID:WillBrennan,项目名称:cpp-elasticsearch,代码行数:39,代码来源:elasticsearch.cpp
注:本文中的json::Object类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论