本文整理汇总了C++中JsonTree::getChild方法的典型用法代码示例。如果您正苦于以下问题:C++ JsonTree::getChild方法的具体用法?C++ JsonTree::getChild怎么用?C++ JsonTree::getChild使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JsonTree
的用法示例。
在下文中一共展示了JsonTree::getChild方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: exception
std::vector<Joint *> SkeletonData::LoadSkeleton(std::string filePath) {
//Not sure about this error catching setup
std::vector<Joint*> joints;
if( PathFileExistsA(filePath.c_str()) == TRUE) {
try{
JsonTree doc = JsonTree(loadFile(filePath));
JsonTree jointsJson = doc.getChild( "joints" );
Joint * parent = nullptr;
unsigned int i = 0;
for( JsonTree::ConstIter joint = jointsJson.begin(); joint != jointsJson.end(); ++joint ) {
// Apparently, getKey DOESN't return an index if there is no key? (Even though it says it will in the json.h header...)
//JsonTree jJson = jointsJson.getChild(joint->getKey());
JsonTree jJson = jointsJson.getChild(i);
Joint * j = readJoint(jJson);
joints.push_back(j);
i++;
}
}catch (std::exception ex) {
//throw ex;
throw std::exception("Invalid File Format. File may be out of date.");
}
}else{
throw std::exception("File does not exist!");
}
return joints;
}
示例2: readAnimations
void SkeletonData::readAnimations(JsonTree animations, Joint * j){
readAnimation(animations.getChild("translateX"), j->translateX);
readAnimation(animations.getChild("translateY"), j->translateY);
readAnimation(animations.getChild("translateZ"), j->translateZ);
readAnimation(animations.getChild("rotate"), j->rotate);
readAnimation(animations.getChild("scaleX"), j->scaleX);
readAnimation(animations.getChild("scaleY"), j->scaleY);
readAnimation(animations.getChild("scaleZ"), j->scaleX);
}
示例3: JsonTree
std::string Server::sendVkSharePlus()
{
if (!RELEASE_VER) return SERVER_OK;
std::map<string,string> strings;
strings.insert(pair<string, string>( "action" , "cnt"));
strings.insert(pair<string, string>( "cnt" , "1"));
strings.insert(pair<string, string>( "type" , "vk"));
string request = Curl::post( SERVER"/save.php", strings);
JsonTree jTree;
try
{
jTree = JsonTree(request);
console()<<"VKONTAKTE PLUS "<< jTree.getChild("cnt").getValue()<<std::endl;
return SERVER_OK;
}
catch(...)
{
}
return SERVER_ERROR;
}
示例4: loadSettings
void PretzelGlobal::loadSettings(fs::path settingsPath){
fs::path loadPath = settingsPath;
if (loadPath.string() == ""){
loadPath = getAppPath() / "guiSettings" / "settings.json";
}
if (!fs::exists(loadPath)){
console() << loadPath << " does not exist" << endl;
}
else{
JsonTree loadTree(loadFile(loadPath));
JsonTree appSettings = loadTree.getChild(0);
for (int i = 0; i < mParamList.size(); i++){
string pName = mParamList[i].name;
switch (mParamList[i].type){
case _FLOAT:
if (appSettings.hasChild(pName)){
float fVal = appSettings.getChild(pName).getValue<float>();
*((float*)mParamList[i].value) = fVal;
}
break;
case _INT:
if (appSettings.hasChild(pName)){
int fVal = appSettings.getChild(pName).getValue<int>();
*((int*)mParamList[i].value) = fVal;
}
break;
case _BOOL:
if (appSettings.hasChild(pName)){
bool bVal = appSettings.getChild(pName).getValue<float>();
*((bool*)mParamList[i].value) = bVal;
}
break;
default:
console() << "Pretzel :: Can't load settings type " << endl;
break;
}
}
}
}
示例5: sendToServerThread
void EmailForm::sendToServerThread()
{
ci::ThreadSetup threadSetup; // instantiate this if you're talking to Cinder from a secondary thread
isSendingToServer = true;
string allEmails = "";
for (size_t i = 0; i < emailVector.size(); i++)
{
if ( i != emailVector.size()-1)
{
allEmails +=emailVector[i] +",";
}
else allEmails +=emailVector[i];
}
console()<<"SEND TO EMAILS:: "<<allEmails<<std::endl;
std::map<string,string> strings;
strings.insert(pair<string, string>( "action" , "mail"));
strings.insert(pair<string, string>( "id" , Params::sessionId));
strings.insert(pair<string, string>( "email" , allEmails));
string request = Curl::post( SERVER"/save.php", strings);
JsonTree jTree;
console()<<"SERVER ANSWER TO SEND MAILS "<<request<<std::endl;
try
{
jTree = JsonTree(request);
string success = jTree.getChild("success").getValue();
if (success == "1")
{
SERVER_STATUS = "OK";
}
else
{
SERVER_STATUS = "ERROR";
touchKeyBoard.removeHandlers();
}
}
catch (... )
{
SERVER_STATUS = "ERROR";
touchKeyBoard.removeHandlers();
}
isSendingToServer = false;
serverThread->detach();
}
示例6: fromJson
void ColorCubePoints::fromJson(const JsonTree &tree)
{
clear();
mOrigin = tree.getValueForKey<float>("origin");
const JsonTree& points = tree.getChild("points");
for (unsigned i = 0; i < points.getNumChildren(); i++) {
const JsonTree& point = points.getChild(i);
push(point.getValueAtIndex<float>(0),
point.getValueAtIndex<float>(1),
point.getValueAtIndex<float>(2));
}
}
示例7: fromJson
//! from json
void WarpPerspectiveBilinear::fromJson(const JsonTree &json)
{
Warp::fromJson(json);
if (json.hasChild("warp")) {
JsonTree warp(json.getChild("warp"));
// get corners
JsonTree corners(warp.getChild("corners"));
for (size_t i = 0; i < corners.getNumChildren(); i++) {
JsonTree child = corners.getChild(i);
float x = (child.hasChild("x")) ? child.getValueForKey<float>("x") : 0.0f;
float y = (child.hasChild("y")) ? child.getValueForKey<float>("y") : 0.0f;
mWarp->setControlPoint(i, vec2(x, y));
CI_LOG_V("corner:" + toString(x) + " " + toString(y));
}
}
}
示例8: load
void View::load( const JsonTree &data )
{
if( data.hasChild( "SUBVIEWS" ) && mLoadSubViews )
{
JsonTree tree = data.getChild( "SUBVIEWS" );
int numSubViews = tree.getNumChildren();
for(int i = 0; i < numSubViews; i++)
{
JsonTree sub = tree[i];
ViewRef subview = getSubView( sub.getValueForKey( "NAME" ) );
if( subview )
{
subview->load( sub );
}
}
}
}
示例9: serviceTweets
// Function the background thread lives in
void TweetStream::serviceTweets()
{
ThreadSetup threadSetup;
std::string nextQueryString = "?q=" + Url::encode( mSearchPhrase );
JsonTree searchResults;
JsonTree::ConstIter resultIt = searchResults.end();
// This function loops until the app quits. Each iteration a pulls out the next result from the Twitter API query.
// When it reaches the last result of the current query it issues a new one, based on the "refresh_url" property
// of the current query.
// The loop doesn't spin (max out the processor) because ConcurrentCircularBuffer.pushFront() non-busy-waits for a new
// slot in the circular buffer to become available.
while( ! mCanceled ) {
if( resultIt == searchResults.end() ) { // are we at the end of the results of this JSON query?
// issue a new query
try {
JsonTree queryResult = queryTwitter( nextQueryString );
// the next query will be the "refresh_url" of this one.
nextQueryString = queryResult["refresh_url"].getValue();
searchResults = queryResult.getChild( "results" );
resultIt = searchResults.begin();
}
catch( ci::Exception &exc ) {
// our API query failed: put up a "tweet" with our error
CI_LOG_W( "exception caught parsing query: " << exc.what() );
mBuffer.pushFront( Tweet( "Twitter API query failed", "sadness", SurfaceRef() ) );
ci::sleep( 2000 ); // try again in 2 seconds
}
}
if( resultIt != searchResults.end() ) {
try {
// get the URL and load the image for this profile
Url profileImgUrl = (*resultIt)["profile_image_url"].getValue<Url>();
SurfaceRef userIcon = Surface::create( loadImage( loadUrl( profileImgUrl ) ) );
// pull out the text of the tweet and replace any XML-style escapes
string text = replaceEscapes( (*resultIt)["text"].getValue() );
string userName = (*resultIt)["from_user"].getValue();
mBuffer.pushFront( Tweet( text, userName, userIcon ) );
}
catch( ci::Exception &exc ) {
CI_LOG_W( "exception caught parsing search results: " << exc.what() );
}
++resultIt;
}
}
}
示例10: postPhotoTweet
bool Twitter::postPhotoTweet(string status, vector<string> filesPath)
{
if (!isAuthFlowComplete) return false;
int max_media_per_upload;
std::string replyMsg = "";
if( twitterObj.getTwitterConfiguration())
{
twitterObj.getLastWebResponse( replyMsg );
try
{
JsonTree jTree = JsonTree(replyMsg);
max_media_per_upload = atoi(jTree.getChild("max_media_per_upload").getValue().c_str());
}
catch(...){};
}
else
{
twitterObj.getLastCurlError( replyMsg );
console()<<"twitterClient:: twitCurl::statusUpdate error: "<< replyMsg.c_str()<<std::endl;
return false;
}
vector<string> filelinks;
for (int i = 0; i < max_media_per_upload; i++)
{
console()<<"path :: "<<filesPath[i]<<std::endl;
filelinks.push_back(filesPath[i]);
}
if( twitterObj.uploadPictureFromFile(filelinks, Utils::cp1251_to_utf8(status.c_str()) ))
{
twitterObj.getLastWebResponse( replyMsg );
console()<<"twitterClient:: twitCurl:: statusUpdate web response: "<< replyMsg.c_str()<<std::endl;
return true;
}
else
{
twitterObj.getLastCurlError( replyMsg );
console()<<"twitterClient:: twitCurl:: statusUpdate error: "<< replyMsg.c_str()<<std::endl;
return false;
}
}
示例11: warp
//! to json
JsonTree WarpPerspectiveBilinear::toJson() const
{
JsonTree json = WarpBilinear::toJson();
if (json.hasChild("warp")) {
JsonTree warp(json.getChild("warp"));
// set corners
JsonTree corners = JsonTree::makeArray("corners");
for (unsigned i = 0; i < 4; ++i) {
vec2 corner = mWarp->getControlPoint(i);
JsonTree cr;
cr.addChild(ci::JsonTree("corner", i));
cr.addChild(ci::JsonTree("x", corner.x));
cr.addChild(ci::JsonTree("y", corner.y));
corners.pushBack(cr);
}
warp.pushBack(corners);
json.pushBack(warp);
}
return json;
}
示例12: sendToServerPrintInfo
std::string Server::sendToServerPrintInfo()
{
if (!RELEASE_VER) return SERVER_OK;
std::map<string,string> strings;
strings.insert(pair<string, string>( "action" , "print_count"));
strings.insert(pair<string, string>( "cnt" , "1"));
string request = Curl::post( SERVER"/save.php", strings);
JsonTree jTree;
try
{
jTree = JsonTree(request);
console()<<"PHOTO NUMS "<< jTree.getChild("cnt").getValue()<<std::endl;
return SERVER_OK;
}
catch(...)
{
}
return SERVER_ERROR;
}
示例13: loadFaces
void FaceController::loadFaces()
{
/*
JsonTree faces( doc.getChild( "faces" ) );
facesStoreVector.clear();
for( JsonTree::ConstIter face = faces.begin(); face != faces.end(); ++face ) {
FaceObject newFace;
vector<Vec2f> points;
string name = face->getChild( "texname" ).getValue<string>();
gl::Texture tex;
try{
tex = loadImage(getAppPath() /FACE_STORAGE_FOLDER/name);
}
catch(...)
{
continue;
}
JsonTree datas =JsonTree( face->getChild( "data" ));
for( JsonTree::ConstIter data = datas.begin(); data != datas.end(); ++data ) {
float x = data->getChild( "x" ).getValue<float>();
float y = data->getChild( "y" ).getValue<float>();
points.push_back(Vec2f(x,y));
}
newFace.setPoints(points);
newFace.setTexName(name);
newFace.setTexture(tex);
facesStoreVector.push_back(newFace);
} */
facesStoreVector.clear();
string path = getAppPath().string() + JSON_STORAGE_FOLDER;
fs::path p(path);
for (fs::directory_iterator it(p); it != fs::directory_iterator(); ++it)
{
if (fs::is_regular_file(*it))
{
JsonTree doc;
try{
doc = JsonTree(loadFile(getAppPath() / JSON_STORAGE_FOLDER / it->path().filename().string()));
}
catch(...)
{
return;
}
JsonTree faces( doc.getChild( "faces" ) );
for( JsonTree::ConstIter face = faces.begin(); face != faces.end(); ++face )
{
FaceObject newFace;
vector<Vec2f> points;
string name = face->getChild( "texname" ).getValue<string>();
gl::Texture tex;
try{
tex = loadImage(getAppPath() /FACE_STORAGE_FOLDER/name);
}
catch(...)
{
continue;
}
JsonTree datas =JsonTree( face->getChild( "data" ));
for( JsonTree::ConstIter data = datas.begin(); data != datas.end(); ++data )
{
float x = data->getChild( "x" ).getValue<float>();
float y = data->getChild( "y" ).getValue<float>();
points.push_back(Vec2f(x,y));
}
newFace.setPoints(points);
newFace.setTexName(name);
newFace.setTexture(tex);
facesStoreVector.push_back(newFace);
}
}
}
}
示例14: getChattyPostDataRefFromJSONPost
ChattyPostDataRef getChattyPostDataRefFromJSONPost(const JsonTree& post)
{
ChattyPostDataRef post_data_ref = ChattyPostData::create();
post_data_ref->m_id = fromString<uint32_t>(post["id"].getValue());
post_data_ref->m_thread_id = fromString<uint32_t>(post["threadId"].getValue());
post_data_ref->m_parent_id = fromString<uint32_t>(post["parentId"].getValue());
post_data_ref->m_author = post["author"].getValue();
post_data_ref->m_body = post["body"].getValue();
replaceEncodingsInString(post_data_ref->m_body);
std::string strvalue = post["category"].getValue();
if(strvalue.length() > 0)
{
if(strvalue == "ontopic") post_data_ref->m_category = category_type::NORMAL;
else if(strvalue == "nws") post_data_ref->m_category = category_type::NWS;
else if(strvalue == "stupid") post_data_ref->m_category = category_type::STUPID;
else if(strvalue == "political") post_data_ref->m_category = category_type::POLITICAL;
else if(strvalue == "tangent") post_data_ref->m_category = category_type::OFFTOPIC;
else if(strvalue == "informative") post_data_ref->m_category = category_type::INFORMATIVE;
else if(strvalue == "nuked") post_data_ref->m_category = category_type::NUKED;
}
strvalue = post["date"].getValue();
if(strvalue.length() > 0)
{
std::tm post_time;
memset(&post_time, 0, sizeof(std::tm));
#if defined(CINDER_MSW)
sscanf_s(strvalue.c_str(), "%d-%d-%dT%d:%d",
&post_time.tm_year,
&post_time.tm_mon,
&post_time.tm_mday,
&post_time.tm_hour,
&post_time.tm_min);
#else
sscanf(strvalue.c_str(), "%d-%d-%dT%d:%d",
&post_time.tm_year,
&post_time.tm_mon,
&post_time.tm_mday,
&post_time.tm_hour,
&post_time.tm_min);
#endif
post_time.tm_year -= 1900;
post_time.tm_mon -= 1;
#if defined(CINDER_MSW)
post_data_ref->m_date_time = _mkgmtime(&post_time);
#else
post_data_ref->m_date_time = timegm(&post_time); // and I have no idea if this is right
#endif
// if mac doesn't have _mkgmtime, need to find a way to convert UTC to local
//post_data_ref->m_date_time = std::mktime(&post_time);
}
if(post.hasChild("lols"))
{
const JsonTree& lols = post.getChild("lols");
for(size_t lol_i = 0; lol_i < lols.getNumChildren(); lol_i++)
{
const JsonTree& lol = lols.getChild(lol_i);
strvalue = lol["tag"].getValue();
if(strvalue.length() > 0)
{
lol_type which_lol = LOL;
if(strvalue == "lol") which_lol = lol_type::LOL;
else if(strvalue == "inf") which_lol = lol_type::INF;
else if(strvalue == "unf") which_lol = lol_type::UNF;
else if(strvalue == "tag") which_lol = lol_type::TAG;
else if(strvalue == "wtf") which_lol = lol_type::WTF;
else if(strvalue == "ugh") which_lol = lol_type::UGH;
post_data_ref->m_lol_count[which_lol] = fromString<unsigned int>(lol["count"].getValue());
}
}
}
return post_data_ref;
}
示例15: getNewEvents
void TreeHeartbeat::getNewEvents()
{
try
{
JsonTree queryResult = queryWinChattyv2Server("waitForEvent?lastEventId=" + toString(m_last_event_id));
if(queryResult.hasChild("lastEventId"))
{
std::string strvalue = queryResult["lastEventId"].getValue();
if(strvalue.length() > 0)
{
m_last_event_id = fromString<uint32_t>(strvalue);
}
if(queryResult.hasChild("events"))
{
AppMessageRef worldTreeEventMessage = AppMessage::create(AppMessage::message_type::WORLDTREE_EVENT);
const JsonTree& events = queryResult.getChild("events");
for(size_t event_i = 0; event_i < events.getNumChildren(); event_i++)
{
const JsonTree& this_event = events.getChild(event_i);
const JsonTree& event_data = this_event.getChild("eventData");
strvalue = this_event["eventType"].getValue();
if(strvalue == "newPost")
{
const JsonTree& post = event_data.getChild("post");
worldTreeEventMessage->AsWorldTreeEvent()->m_new_posts_list.push_front(getChattyPostDataRefFromJSONPost(post));
}
else if(strvalue == "categoryChange")
{
}
else if(strvalue == "serverMessage")
{
}
else if(strvalue == "lolCountsUpdate")
{
}
}
sortChattyPostDataList(worldTreeEventMessage->AsWorldTreeEvent()->m_new_posts_list);
if(!m_canceled)
{
((LampApp*)app::App::get())->postMessage(worldTreeEventMessage);
}
}
}
else
{
ci::sleep(2000.0f);
}
}
catch(ci::Exception& exc)
{
CI_LOG_E("Error calling WCv2 method waitForEvent: " << exc.what());
ci::sleep(2000.0f);
}
}