本文整理汇总了C++中JsonTree::getKey方法的典型用法代码示例。如果您正苦于以下问题:C++ JsonTree::getKey方法的具体用法?C++ JsonTree::getKey怎么用?C++ JsonTree::getKey使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JsonTree
的用法示例。
在下文中一共展示了JsonTree::getKey方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: pushBack
void JsonTree::pushBack( const JsonTree &newChild )
{
if( newChild.getKey() == "" )
mNodeType = NODE_ARRAY;
else
mNodeType = NODE_OBJECT;
mChildren.push_back( newChild );
mChildren.back().mParent = this;
mValue = "";
}
示例2: setup
void JsonTestApp::setup()
{
JsonTree value( "key", "value" );
console() << value << endl;
JsonTree doc( loadResource( RES_JSON ) );
JsonTree musicLibrary( doc.getChild( "library" ) );
JsonTree owner = doc.getChild( "library.owner" );
for( JsonTree::ConstIter item = owner.begin(); item != owner.end(); ++item ) {
console() << "Node: " << item->getKey() << " Value: " << item->getValue<string>() << endl;
}
JsonTree tracks = doc.getChild( "library.albums[0].tracks" );
for( JsonTree::ConstIter track = tracks.begin(); track != tracks.end(); ++track ) {
console() << track->getChild( "id" ).getValue<int>() << endl;
}
for( JsonTree::ConstIter trackIt = tracks.begin(); trackIt != tracks.end(); ++trackIt ) {
JsonTree track = * trackIt;
console() << track["id"].getValue<int>() << endl;
}
JsonTree firstAlbum = doc.getChild( "library.albums[0]" );
for( JsonTree::Iter child = firstAlbum.begin(); child != firstAlbum.end(); ++child ) {
if ( !child->hasChildren() ) {
console() << "Key: " << child->getKey() << " Value: " << child->getValue<string>() << endl;
}
}
console() << doc.getChild( "library.owner" );
JsonTree &ownerCity = doc.getChild( "library.owner.city" );
string s = ownerCity.getPath();
console() << "Path: " << ownerCity.getPath() << "\n Value: " << ownerCity.getValue<string>() << std::endl;
console() << doc;
JsonTree firstTrackCopy = doc.getChild( "library.albums[0].tracks[0].title" );
firstTrackCopy = JsonTree( firstTrackCopy.getKey(), string( "Replacement name" ) );
console() << doc.getChild( "library.albums[0].tracks[0]['title']" ) << std::endl;
JsonTree &firstTrackRef = doc.getChild( "library.albums[0].tracks[2].title" );
console() << firstTrackRef.getPath() << std::endl;
firstTrackRef = JsonTree( firstTrackRef.getKey(), string( "Replacement name" ) );
console() << doc.getChild( "library.albums[0].tracks[0].title" ) << std::endl;
try {
JsonTree invalid( "%%%%%%%%" );
} catch ( JsonTree::ExcJsonParserError ex ) {
console() << ex.what() << std::endl;
}
}