本文整理汇总了C++中JsonTree::replaceChild方法的典型用法代码示例。如果您正苦于以下问题:C++ JsonTree::replaceChild方法的具体用法?C++ JsonTree::replaceChild怎么用?C++ JsonTree::replaceChild使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JsonTree
的用法示例。
在下文中一共展示了JsonTree::replaceChild方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: mouseDown
void JsonTestApp::mouseDown( MouseEvent event )
{
JsonTree doc;
JsonTree library = JsonTree::makeObject( "library" );
JsonTree album = JsonTree::makeArray( "album" );
album.pushBack( JsonTree( "musician", string( "Sufjan Stevens" ) ) );
album.pushBack( JsonTree( "year", string( "2004" ) ) );
album.pushBack( JsonTree( "title", string( "Seven Swans" ) ) );
JsonTree tracks = JsonTree::makeArray( "tracks" );
for ( int32_t i = 0; i < 6; i ++ ) {
JsonTree track;
track.pushBack( JsonTree( "id", i + 1 ) );
JsonTree title;
switch ( i ) {
case 0:
title = JsonTree( "title", "All the Trees of the Field Will Clap Their Hands" );
break;
case 1:
title = JsonTree( "title", "The Dress Looks Nice on You" );
break;
case 2:
title = JsonTree( "title", "In the Dev Hole's Territory" );
break;
case 3:
title = JsonTree( "title", "To Be a Clone With You" );
break;
case 4:
title = JsonTree( "title", "To Be Removed" );
break;
case 5:
title = JsonTree( "title", "To Be Removed" );
break;
}
track.pushBack( title );
tracks.pushBack( track );
}
for ( JsonTree::Iter trackIt = tracks.begin(); trackIt != tracks.end(); ++trackIt ) {
if ( trackIt->getChild( "id" ).getValue<int>() == 3 ) {
JsonTree track;
track.pushBack( JsonTree( "id", 3 ) );
track.pushBack( JsonTree( "title", "In the Devil's Territory" ) );
tracks.replaceChild( trackIt, track );
}
}
JsonTree track;
track.pushBack( JsonTree( "id", 4 ) );
track.pushBack( JsonTree( "title", "To Be Alone With You" ) );
tracks.replaceChild( 3, track );
tracks.removeChild( 4 );
for ( JsonTree::Iter trackIt = tracks.begin(); trackIt != tracks.end(); ) {
if ( trackIt->getChild( "id" ).getValue<int>() == 6 ) {
trackIt = tracks.removeChild( trackIt );
} else {
++trackIt;
}
}
album.pushBack( tracks );
library.pushBack( album );
doc.pushBack( library );
console() << doc;
doc.write( writeFile( getDocumentsDirectory() + "testoutput.json" ), false );
}