当前位置: 首页>>代码示例>>C++>>正文


C++ json::StyledWriter类代码示例

本文整理汇总了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();

}
开发者ID:BioinformaticsArchive,项目名称:TTT,代码行数:27,代码来源:jsontissuetrackingproject.cpp

示例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;
}
开发者ID:ChunHungLiu,项目名称:freeminer,代码行数:31,代码来源:l_util.cpp

示例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();
	}
}
开发者ID:kolhammer,项目名称:Psybrus,代码行数:33,代码来源:CsCore.cpp

示例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;
  }
开发者ID:Omel,项目名称:xbmc,代码行数:25,代码来源:fortherecordrpc.cpp

示例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;
开发者ID:LTears,项目名称:chromeExtInstaller,代码行数:31,代码来源:extInstaller.cpp

示例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() );
}
开发者ID:RudyOddity,项目名称:Cinder,代码行数:28,代码来源:Json.cpp

示例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;
}
开发者ID:CourseReps,项目名称:ECEN489-Fall2014,代码行数:34,代码来源:JSONtest2.cpp

示例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;

}
开发者ID:vineelal,项目名称:queralyzer,代码行数:30,代码来源:q_MetaData.cpp

示例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);
}
开发者ID:Vanuan,项目名称:iviLink,代码行数:34,代码来源:cstateupdater.cpp

示例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;
}
开发者ID:summerbreezeex,项目名称:GitHubStation,代码行数:28,代码来源:TestJsonCpp.cpp

示例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);
      }
  }
开发者ID:Fourni-j,项目名称:EpitechSpider,代码行数:25,代码来源:Config.cpp

示例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;
  }
开发者ID:milhcbt,项目名称:OrthancMirror,代码行数:25,代码来源:RestApiOutput.cpp

示例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;
}
开发者ID:Yinxiaoli,项目名称:code,代码行数:27,代码来源:structured_svm.cpp

示例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());
	}
}
开发者ID:roule-marcel,项目名称:webrtcpp,代码行数:25,代码来源:SignalingServer.cpp

示例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;
        }
    }
开发者ID:anicloud,项目名称:ops-reload,代码行数:26,代码来源:test_MockMaster.cpp


注:本文中的json::StyledWriter类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。