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


C++ JSONNode::Parse方法代码示例

本文整理汇总了C++中JSONNode::Parse方法的典型用法代码示例。如果您正苦于以下问题:C++ JSONNode::Parse方法的具体用法?C++ JSONNode::Parse怎么用?C++ JSONNode::Parse使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在JSONNode的用法示例。


在下文中一共展示了JSONNode::Parse方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1:

// ****************************************************************************
// Method: SharedDaemon::handleConnection
//
// Purpose:
//  Handle the incomming connection..
//
// Arguments:
//
// Returns:
//
// Note:
//
// Programmer: Hari Krishnan
// Creation:   Oct 13, 2012
//
// Modifications:
//   Kathleen Biagas, Mon Dec 3 12:01:15 PST 2012
//   Use operator[] instead of 'at' to support older MSVC compiler.
//
// ****************************************************************************
bool
SharedDaemon::ParseInput(const QString& input, JSONNode& output)
{
    if(input.startsWith("{"))
    {
        JSONNode node;
        node.Parse(input.toStdString());
        //std::cout << node.ToString() << std::endl;
        /// also check to make sure password is coorect..
        if(node.GetType() != JSONNode::JSONOBJECT ||
           !node.HasKey("password") ||
            node.GetJsonObject()["password"].GetString() != password.toStdString())
            return false;

        output = node;
        return true;
    }

    return false;
}
开发者ID:burlen,项目名称:visit_vtk_7_src,代码行数:40,代码来源:SharedDaemon.C

示例2: ConnectToExistingViewer

bool ViewerProxy::ConnectToExistingViewer(const std::string& host, const int& port, const std::string& password)
{

    //Step 1: Check and see if connection can be made..
    int testSocket = socket(AF_INET, SOCK_STREAM, 0);
    if( testSocket < 0 )
    {
        std::cerr << "Socket not created (ERROR)" << std::endl;
        return false;
    }

    std::cout << "connecting to host: " << host << " port " << port << std::endl;
    struct sockaddr_in sin;
    struct hostent *server = gethostbyname(host.c_str());
    memset(&sin, 0, sizeof(sin));
    memcpy(&(sin.sin_addr), server->h_addr, server->h_length);
    sin.sin_family = AF_INET;
    sin.sin_port = htons(port);

    if (connect(testSocket,(struct sockaddr*) &sin,sizeof(sin)) < 0)
    {
        std::cerr << "Unable to connect to Viewer" << std::endl;
        CloseSocket(testSocket);
        return false;
    }

    //Step 2: Send password to verify that you should be added
    std::ostringstream handshake;
    handshake << "{ \"password\" : \"" << password << "\" }";

#ifndef _WIN32
    int nwrite = write(testSocket,handshake.str().c_str(),handshake.str().length());
#else
    int nwrite = _write(testSocket,handshake.str().c_str(),(unsigned int)handshake.str().length());
#endif
    if(nwrite < 0)
    {
        std::cerr << "Error writing to Viewer" << std::endl;
        CloseSocket(testSocket);
        return false;
    }

    //Step 3: receive arguments to establish reverse connection

    char buffer[1024];

#ifndef _WIN32
    int bytes = read(testSocket,buffer,1024);
#else
    int bytes = _read(testSocket,buffer,1024);
#endif
    buffer[bytes] = '\0';
    //std::cout << "bytes read: " << bytes << " " << buffer << std::endl;

    CloseSocket(testSocket);
    //Step 4: reverse connect same as if it was originally intented..

    //parse message and create new reverse connect

    std::string message = buffer;

    JSONNode node;
    node.Parse(message);

    stringVector args;

    args.push_back("-v");
    args.push_back(node.GetJsonObject()["version"].GetString());

    args.push_back("-host");
    args.push_back(node.GetJsonObject()["host"].GetString());

    args.push_back("-port");
    args.push_back(node.GetJsonObject()["port"].GetString());

    args.push_back("-key");
    args.push_back(node.GetJsonObject()["securityKey"].GetString());

    args.push_back("-reverse_launch");

    int inputArgc = args.size();

    char** inputArgv = new char* [inputArgc+1];

    for(size_t i = 0; i < args.size(); ++i)
    {
        inputArgv[i] = new char [args[i].length()+1];
        strcpy(inputArgv[i],args[i].c_str());
        inputArgv[i][args[i].length()] = '\0';
    }

    inputArgv[inputArgc] = NULL;

    // Connect to the viewer process. Our command line arguments
    // should contain  The viewer is executed using
    // "visit -viewer".
    //

    viewerP = new ParentProcess;
    viewerP->Connect(1, 1, &inputArgc, &inputArgv, true);
//.........这里部分代码省略.........
开发者ID:burlen,项目名称:visit_vtk_7_src,代码行数:101,代码来源:ViewerProxy.C

示例3: mapnode

int
SocketConnection::Fill()
{
    if(destFormat.Format == TypeRepresentation::ASCIIFORMAT)
    {
        std::string xmlString = "";

        char tmp[1001]; //leave 1 for null termination//

        int amountRead = 0;
        do
        {

#if defined(_WIN32)
            int amountRead = recv(descriptor, (char FAR *)tmp, 1000, 0);
            if(amountRead == SOCKET_ERROR)
            {
                LogWindowsSocketError("SocketConnection", "Fill");
                if(WSAGetLastError() == WSAEWOULDBLOCK)
                    return -1;
            }
#else
            amountRead = recv(descriptor, (void *)tmp, 1000, 0);
#endif

            if(amountRead > 0)
            {
                zeroesRead = 0;
                tmp[amountRead] = 0;
                xmlString += tmp;
            }

            ++zeroesRead;

            // If we have had a certain number of zero length reads in a row,
            // assume the connection died.
            if(zeroesRead > 100)
            {
                 EXCEPTION0(LostConnectionException);
            }
        }while(amountRead == 1000); //if it gets entire list..
        if(xmlString.size() > 0)
        {
            JSONNode node;
            node.Parse(xmlString);

            //std::cout << node.ToString() << std::endl;

            int guido = node["id"].GetInt();

            JSONNode contents = node["contents"];
//            JSONNode metadata = node["typeinfo"];

            /// With the information I have I could probably
            /// just use JSONNode to convert completely..
            /// but that would leave MapNode incomplete..

            MapNode mapnode(contents,false);

            //std::cout << mapnode.ToXML(false) << std::endl;
            //std::cout << metadata["data"] << std::endl;

            buffer.clear();
            return Write(guido,&mapnode); //,&metadata["data"]
        }

        return 0;
    }

    unsigned char tmp[1000];
#if defined(_WIN32)
    int amountRead = recv(descriptor, (char FAR *)tmp, 1000, 0);
    if(amountRead == SOCKET_ERROR)
    {
        LogWindowsSocketError("SocketConnection", "Fill");
        if(WSAGetLastError() == WSAEWOULDBLOCK)
            return -1;
    }
#else
    int amountRead = recv(descriptor, (void *)tmp, 1000, 0);
#endif

    if(amountRead > 0)
    {
        zeroesRead = 0;

        // Add the new bytes to the buffer.
        for(int i = 0; i < amountRead; ++i)
            buffer.push_back(tmp[i]);
    }
    else
        ++zeroesRead;

    // If we have had a certain number of zero length reads in a row,
    // assume the connection died.
    if(zeroesRead > 100)
    {
         EXCEPTION0(LostConnectionException);
    }

//.........这里部分代码省略.........
开发者ID:HarinarayanKrishnan,项目名称:VisIt26RC_Trunk,代码行数:101,代码来源:SocketConnection.C


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