Exemplo n.º 1
0
void JsonTree::write( DataTargetRef target, bool createDocument )
{
	// Declare output string
	string jsonString = "";

	try {
		
		// Create JsonCpp data to send to parser
		Json::Value value = createNativeDoc( createDocument );

		// This routine serializes JsonCpp data and formats it
		Json::StyledWriter writer;
		jsonString = writer.write( value.toStyledString() );
		boost::replace_all( jsonString, "\\n", "\r\n" );
		boost::replace_all( jsonString, "\\\"", "\"" );
		if( jsonString.length() >= 3 ) {
			jsonString = jsonString.substr( 1, boost::trim_copy( jsonString ).length() - 2 );
		}
		jsonString += "\0";
	}
	catch ( ... ) {
		throw ExcJsonParserError( "Unable to serialize JsonTree." );
	}

	// Save data to file
	OStreamRef os = target->getStream();
	os->writeData( jsonString.c_str(), jsonString.length() );
}
Exemplo n.º 2
0
Arquivo: Xml.cpp Projeto: Ahbee/Cinder
void XmlTree::write( DataTargetRef target, bool createDocument )
{
	// this could do with a more efficient implementation
	shared_ptr<rapidxml::xml_document<char> > doc = createRapidXmlDoc( createDocument );
	OStreamRef os = target->getStream();
	std::ostringstream ss;
	ss << *doc;
	os->writeData( ss.str().c_str(), ss.str().length() );
}