本文整理汇总了C++中json::StyledWriter类的典型用法代码示例。如果您正苦于以下问题:C++ StyledWriter类的具体用法?C++ StyledWriter怎么用?C++ StyledWriter使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了StyledWriter类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: file
void ttt::JSONTissueTrackingProject::StoreFrameInfo(){
Json::Value root;
Json::StyledWriter writer;
root["platenessSteps"]=this->m_PlatenessSteps;
root["platenessHighestScale"]=this->m_HighestPlatenessScale;
root["platenessLowestScale"]=this->m_LowestPlatenessScale;
root["vertexnessSteps"]=this->m_VertexnessSteps;
root["vertexnessHighestScale"]=this->m_HighestVertexnessScale;
root["vertexnessLowestScale"]=this->m_LowestVertexnessScale;
std::stringstream fileNameStream;
fileNameStream << m_ProjectPath << "/" << "frame-"<< m_Frame << ".json";
std::string projectConfigFile;
fileNameStream >> projectConfigFile;
std::string jsoncontent=writer.write(root);
std::ofstream file (projectConfigFile.c_str(), std::ofstream::out | std::ofstream::trunc);
file << jsoncontent;
file.close();
}
示例2: l_write_json
// write_json(data[, styled]) -> string or nil and error message
int ModApiUtil::l_write_json(lua_State *L)
{
NO_MAP_LOCK_REQUIRED;
bool styled = false;
if (!lua_isnone(L, 2)) {
styled = lua_toboolean(L, 2);
lua_pop(L, 1);
}
Json::Value root;
try {
read_json_value(L, root, 1);
} catch (SerializationError &e) {
lua_pushnil(L);
lua_pushstring(L, e.what());
return 2;
}
std::string out;
if (styled) {
Json::StyledWriter writer;
out = writer.write(root);
} else {
Json::FastWriter writer;
out = writer.write(root);
}
lua_pushlstring(L, out.c_str(), out.size());
return 1;
}
示例3: saveDependancies
//////////////////////////////////////////////////////////////////////////
// saveDependancy
void CsCore::saveDependancies( const BcPath& FileName )
{
BcPath DependanciesFileName( FileName );
// Append new extension.
DependanciesFileName.append( ".dep" );
//
Json::Value Object( Json::arrayValue );
if( DependancyMap_.find( *FileName ) != DependancyMap_.end() )
{
CsDependancyList& DependancyList = DependancyMap_[ *FileName ];
for( CsDependancyListIterator It( DependancyList.begin() ); It != DependancyList.end(); ++It )
{
Object.append( saveDependancy( (*It) ) );
}
}
// Output using styled writer.
Json::StyledWriter Writer;
std::string JsonOutput = Writer.write( Object );
BcFile OutFile;
if( OutFile.open( (*DependanciesFileName).c_str(), bcFM_WRITE ) )
{
OutFile.write( JsonOutput.c_str(), JsonOutput.size() );
OutFile.close();
}
}
示例4: KeepLiveStreamAlive
bool KeepLiveStreamAlive()
{
//Example request:
//{"CardId":"String content","Channel":{"BroadcastStart":"String content","BroadcastStop":"String content","ChannelId":"1627aea5-8e0a-4371-9022-9b504344e724","ChannelType":0,"DefaultPostRecordSeconds":2147483647,"DefaultPreRecordSeconds":2147483647,"DisplayName":"String content","GuideChannelId":"1627aea5-8e0a-4371-9022-9b504344e724","LogicalChannelNumber":2147483647,"Sequence":2147483647,"Version":2147483647,"VisibleInGuide":true},"RecorderTunerId":"1627aea5-8e0a-4371-9022-9b504344e724","RtspUrl":"String content","StreamLastAliveTime":"\/Date(928142400000+0200)\/","StreamStartedTime":"\/Date(928142400000+0200)\/","TimeshiftFile":"String content"}
//Example response:
//true
if(!g_current_livestream.empty())
{
Json::StyledWriter writer;
std::string arguments = writer.write(g_current_livestream);
Json::Value response;
int retval = ForTheRecordJSONRPC("ForTheRecord/Control/KeepLiveStreamAlive", arguments, response);
if (retval != E_FAILED)
{
//if (response == "true")
//{
return true;
//}
}
}
return false;
}
示例5: GenerateNativeAppConfig
bool CExtInstaller::GenerateNativeAppConfig()
{
/*
{
"name": "com.baidu.antivirus",
"description": "Chrome Native Messaging API Baidu AntiVirus Host",
"path": "exe path",
"type": "stdio",
"allowed_origins": [
"chrome-extension://afbbkciigbkkonnbcagfkobemjhehfem/"
]
}
*/
Json::Value root;
root["name"] = Json::Value(CHROME_SAMPLE_NATIVE_HOST_NAME);
root["description"] = Json::Value("Chrome Native Messaging API Baidu AntiVirus Host");
std::string nativeAppPath = WtoA(m_CurrentDir +_T("\\") +NAPP_PATH);
root["path"] = Json::Value(nativeAppPath);
root["type"] = Json::Value("stdio");
std::string allowed_origins = "chrome-extension://";
allowed_origins.append(CHROME_SAMPLE_CRX_ID_A);
allowed_origins.append("/");
root["allowed_origins"].append(allowed_origins);
Json::StyledWriter fw;
std::string szOssNativeAppConfig = fw.write(root);
std::ofstream out(GetNativeAppConfigPath().c_str());
out<<szOssNativeAppConfig;
out.close();
return true;
示例6: write
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() );
}
示例7: main
int main() {
Json::Value fromScratch;
Json::Value array;
array.append("hello");
array.append("world");
fromScratch["hello"] = "world";
fromScratch["number"] = 2;
fromScratch["array"] = array;
fromScratch["object"]["hello"] = "world";
output(fromScratch);
// write in a nice readible way
Json::StyledWriter styledWriter;
cout << styledWriter.write(fromScratch);
// ---- parse from string ----
// write in a compact way
Json::FastWriter fastWriter;
std::string jsonMessage = fastWriter.write(fromScratch);
Json::Value parsedFromString;
Json::Reader reader;
bool parsingSuccessful = reader.parse(jsonMessage, parsedFromString);
if (parsingSuccessful)
{
cout << styledWriter.write(parsedFromString) << endl;
}
cin.ignore(1);
return 0;
}
示例8: serialize
bool JsonSerializer::serialize(JsonSerializable *pObj, std::string &output)
{
/* if(pObj==NULL)
return false;
Json::Value serializeRoot;
pObj->serialize(serializeRoot);
Json::StyledWriter writer;
output = writer.write(serializeRoot);
return true;
*/
if(pObj==NULL)
return false;
// treat pObj as an array
Json::ValueType vt = Json::arrayValue;
Json::Value serializeArrayRoot(vt);
Json::Value serializeRoot;
int num_of_elements = sizeof(pObj)/sizeof(JsonSerializable);
for(int i=0; i<num_of_elements; i++)
{
(pObj[i]).serialize(serializeRoot);
serializeArrayRoot[i] = serializeRoot;
}
Json::StyledWriter writer;
output = writer.write(serializeArrayRoot);
return true;
}
示例9: incomingNotification
//Callback for profile created on the other side; notification about seat state
void CStateUpdater::incomingNotification(Json::Value seatState)
{
Json::StyledWriter writer;
std::string deserializedJson = writer.write(seatState);
LOG4CPLUS_INFO(mLogger, "The following state came: "+deserializedJson);
//updating GUI according to the new state
emit showSeat();
int status = seatState.get("currSeat", 0).asInt();
if (status == 0)
{
LOG4CPLUS_INFO(mLogger, "Currently displayed seat is Driver's seat");
emit current_seat_viewDriver();
}
else
{
LOG4CPLUS_INFO(mLogger, "Currently displayed seat is Passenger's seat");
emit current_seat_viewPass();
}
status = seatState.get("heaterDriver", 0).asInt();
emit heaterDriver(status);
status = seatState.get("heaterPass", 0).asInt();
emit heaterPass(status);
status = seatState.get("bottom_x", 0).asInt();
emit bottom_x(status);
status = seatState.get("bottom_y", 0).asInt();
emit bottom_y(status);
status = seatState.get("back_x", 0).asInt();
emit back_x(status);
status = seatState.get("back_y", 0).asInt();
emit back_y(status);
status = seatState.get("back_angle", 0).asInt();
emit back_angle(status);
}
示例10: Run
int UnitTestJsonCpp::Run(void)
{
Json::Value root;
Json::Value arrayObj;
Json::Value item;
for (int i = 0; i < 10; i ++)
{
item["key"] = i;
arrayObj.append(item);
}
root["key1"] = "value1";
root["key2"] = "value2";
root["array"] = arrayObj;
std::string out = root.toStyledString();
std::cout << out << std::endl;
Json::StyledWriter writer;
std::string output = writer.write(root);
std::ofstream out_file("duplicate_config.json" );
out_file << output;
out_file.flush();
return 0;
}
示例11: return
bool Config::addUser(int32_t id, uint32_t token)
{
std::ofstream file("conf/users.json");
Json::Value newUser(Json::objectValue);
Json::StyledWriter writer;
Json::Value::UInt i = _root["users"].size();
if (!file.fail())
{
if ((newUser["id"] = id) == Json::nullValue)
return (false);
if ((newUser["token"] = token) == Json::nullValue)
return (false);
if ((_root["users"][i] = newUser) == Json::nullValue)
return (false);
file << writer.write(_root);
file.close();
return (true);
}
else
{
std::cerr << "can't open the file" << std::endl;
return (false);
}
}
示例12: AnswerJson
void RestApiOutput::AnswerJson(const Json::Value& value)
{
CheckStatus();
if (convertJsonToXml_)
{
#if ORTHANC_PUGIXML_ENABLED == 1
std::string s;
Toolbox::JsonToXml(s, value);
output_.SetContentType("application/xml");
output_.Answer(s);
#else
LOG(ERROR) << "Orthanc was compiled without XML support";
throw OrthancException(ErrorCode_InternalError);
#endif
}
else
{
Json::StyledWriter writer;
output_.SetContentType("application/json");
output_.Answer(writer.write(value));
}
alreadySent_ = true;
}
示例13: Save
bool StructuredSVM::Save(const char *fname, bool saveFull, bool getLock) {
if(getLock) Lock();
Json::Value root;
if(modelfile) free(modelfile);
modelfile = StringCopy(fname);
if(sum_w) root["Sum w"] = sum_w->save();
root["Regularization (C)"] = params.C;
root["Training accuracy (epsilon)"] = params.eps;
root["T"] = (int)t;
if(trainfile) root["Training Set"] = trainfile;
root["Custom"] = Save();
if(saveFull) {
char full_name[1000];
sprintf(full_name, "%s.online", fname);
root["Online Data"] = full_name;
if(!SaveOnlineData(full_name)) { Unlock(); return false; }
}
Json::StyledWriter writer;
FILE *fout = fopen(fname, "w");
if(!fout) { fprintf(stderr, "Couldn't open %s for writing\n", fname); Unlock(); return false; }
fprintf(fout, "%s", writer.write(root).c_str());
fclose(fout);
if(getLock) Unlock();
return true;
}
示例14: sendLocalSDP
void SignalingWebSocketPeer::sendLocalSDP(std::string type, std::string sdp) {
Json::StyledWriter writer;
Json::Value message;
message["type"] = type;
if(sdp.length() > 800) {
for(int i=0; i<sdp.length(); i+=800) {
int n = MIN(sdp.length()-i+1,800);
message["sdpPartial"] = sdp.substr(i, n);
std::string msg = writer.write(message);
send(msg.c_str());
}
message.removeMember("sdpPartial");
message["endSdp"] = "yes";
std::string msg = writer.write(message);
send(msg.c_str());
}
else {
message["sdp"] = sdp;
std::string msg = writer.write(message);
send(msg.c_str());
}
}
示例15: heartbeat
void heartbeat(ThriftHeartbeatResponse& _return, const ThriftHeartbeatMessage& msg)
{
::sailor::MutexLocker locker(&_mutex);
// save msg
HeartbeatMessage matrix_msg = to_matrix(msg);
std::string out;
Json::Value v = matrix_msg.to_json();
Json::StyledWriter writer;
out = writer.write(v);
cout << "============================================================";
cout << out << endl;
cout << "============================================================";
// set response
_return = g_res;
if(g_hb_count > 0) {
g_hb_count --;
}
if(g_hb_count == 0) {
LOG.info("HB count reach, quit");
exit(0);
return;
}
}