int Condition::Compile(JSONNode columns) { if (operand1[0] == '\'') { operand1IsConstant = true; operand1 = operand1.substr(1, operand1.length() - 2); } else { operand1IsConstant = false; bool contains = false; for (auto j = columns.begin(); !contains && j != columns.end(); ++j) if (j->as_string() == operand1) contains = true; if (!contains) return Errors::ERR_NO_COLUMN; } if (operand2[0] == '\'') { operand2IsConstant = true; operand2 = operand2.substr(1, operand2.length() - 2); } else { operand2IsConstant = false; bool contains = false; for (auto j = columns.begin(); !contains && j != columns.end(); ++j) if (j->as_string() == operand2) contains = true; if (!contains) return Errors::ERR_NO_COLUMN; } return Errors::ERR_OK; }
void ParseJSON(const JSONNode & n, std::list<KP_Service > & services){ std::string providerId, serviceId; bool isHasServiceId = false, isHasProviderId = false; JSONNode::const_iterator i = n.begin(); while (i != n.end()){ // recursively call ourselves to dig deeper into the tree if (i -> type() == JSON_ARRAY || i -> type() == JSON_NODE){ ParseJSON(*i, services); } // get the node name and value as a string std::string node_name = i -> name(); //std::cout<< "Name: "<< node_name << endl; // find out where to store the values if (node_name == TAG_SERVICE_STR){ isHasServiceId = true; serviceId = i -> as_string(); } else if (node_name == TAG_PROVIDER_STR){ isHasProviderId = true; providerId = i -> as_string(); } //increment the iterator ++i; } if(isHasServiceId && isHasProviderId) services.push_back(KP_Service (providerId, serviceId)); }
void ProgrammableOpAttributes::AddFunction(const std::string& name, const stringVector& atts) { JSONNode vars = JSONNode::JSONArray(); for(int i = 0; i < atts.size(); ++i) vars.Append(atts[i]); JSONNode node; node["vars"] = vars; std::string argstring = ""; for(size_t i = 0; i < atts.size(); ++i) argstring += atts[i] + (i == atts.size()-1 ? "" : ","); // char buf[1024]; // sprintf(buf,"import visit_internal_funcs\nsetout(visit_internal_funcs.%s(%s))",name.c_str(),argstring.c_str()); std::ostringstream ostr; ostr << "import visit_internal_funcs\n" << "setout(visit_internal_funcs." << name << "(" << argstring << "))" << std::endl; std::string escapedCode = ostr.str(); //std::cout << escapedCode << std::endl; replace(escapedCode, "\n", "\\n"); node["source"] = escapedCode; script["scripts"][name] = node; //update scriptmap scriptMap = script.ToString(); Select(ID_scriptMap, (void *)&scriptMap); }
void ProgrammableOpAttributes::AddPythonScript(const std::string& name, const stringVector& atts, const std::string& code) { JSONNode vars = JSONNode::JSONArray(); for(int i = 0; i < atts.size(); ++i) vars.Append(atts[i]); JSONNode node; node["vars"] = vars; std::ostringstream pwrapper; pwrapper << "from visit_internal_funcs import *\n" << code << "\n"; std::string escapedCode = pwrapper.str(); replace(escapedCode, "\n", "\\n"); node["source"] = escapedCode; script["scripts"][name] = node; //update scriptmap scriptMap = script.ToString(); Select(ID_scriptMap, (void *)&scriptMap); }
static void processModel(const JSONNode & nd, MatModel& model) { bool nlayset = false; bool rangeset = false; bool lengthset = false; bool heightset = false; bool atomsset = false; for (auto i = nd.begin(); i != nd.end(); i++) { if (i->name() == JsonNames::numlayers) { model.mNumLayers = i->as_int(); nlayset = true; } else if (i->name() == JsonNames::range) { model.mRadius = i->as_float(); rangeset = true; } else if (i->name() == JsonNames::length) { model.mLength = i->as_float(); lengthset = true; } else if (i->name() == JsonNames::height) { model.mHeight = i->as_float(); heightset = true; } else if (i->name() == JsonNames::atoms) { BNB_ASSERT(nlayset); readIntVector(*i, model.mNumLayers, model.mLayersAtoms); atomsset = true; } else { BNB_ERROR_REPORT("Illegal name on parsing model data"); } } BNB_ASSERT(nlayset && rangeset && lengthset && heightset && atomsset); }
void ParseJSON(const JSONNode & n){ JSONNode::const_iterator i = n.begin(); while (i != n.end()){ // recursively call ourselves to dig deeper into the tree if (i -> type() == JSON_ARRAY || i -> type() == JSON_NODE){ ParseJSON(*i); } // get the node name and value as a string std::string node_name = i -> name(); // find out where to store the values if (node_name == "RootA"){ rootA = i -> as_string(); } else if (node_name == "ChildA"){ childA = i -> as_string(); } else if (node_name == "ChildB") childB = i -> as_int(); //increment the iterator ++i; } }
bool Programmer::loadJSON(JSONNode data) { auto devices = data.find("devices"); if (devices == data.end()) { Logger::log(ERR, "No devices found in Programmer"); return false; } auto it = devices->begin(); while (it != devices->end()) { Device* device = new Device(it->name(), *it); // We're overwriting data here, so make sure to actually delete the old data. // if there is any if (m_devices.count(device->getId()) > 0) delete m_devices[device->getId()]; m_devices[device->getId()] = device; it++; } auto c = data.find("captured"); if (c == data.end()) { Logger::log(WARN, "No captured set found in Programmer"); captured = DeviceSet(m_rig); } else { captured = DeviceSet(m_rig, *c); } return true; }
void ResUtils::ParseJobsResponse(std::list<KP_Job>& jobs, JSONNode &n) { std::string jobId; JSONNode::const_iterator i = n.begin(); if (i != n.end() && i -> name() == TAG_JOBS_STR && i -> type() == JSON_NODE) { JSONNode::const_iterator ijs = (*i).begin(); if (ijs != n.end() && ijs -> name() == TAG_ITEMS_STR && ijs -> type() == JSON_ARRAY) { JSONNode::const_iterator ij = (*ijs).begin(); while (ij != (*ijs).end()) { if(ij -> type() == JSON_ARRAY || ij -> type() == JSON_NODE) { JSONNode::const_iterator ia = (*ij).begin(); if (ia != (*ij).end() && ia -> name() == TAG_ID_STR && ia -> type() != JSON_ARRAY && ia -> type() != JSON_NODE) { jobId = ia -> as_string(); //cout << "Bp: jobId: " << jobId << endl; jobs.push_back(KP_Job (jobId)); } } ij ++; } } } }
void baiduparser:: _parserJsonS ( const JSONNode & node_tree ) { JSONNode::const_iterator node_iter = node_tree.begin(); while ( node_iter != node_tree.end() ) { string node_name = node_iter->name (); if ( node_name == "data" ) { JSONNode::const_iterator arr_first_elem = node_iter->begin(); JSONNode::const_iterator node_first_elem = arr_first_elem->begin(); while ( node_first_elem != arr_first_elem->end() ) { if ( node_first_elem->name() == "dst" ) { result_ = node_first_elem->as_string(); break; } ++ node_first_elem ; } break; } node_iter ++; } }
//[{"username":"******", "firstname" : "Echo \/ Sound Test Service", "lastname" : null, "avatarUrl" : null, "mood" : null, "richMood" : null, "displayname" : null, "country" : null, "city" : null},...] void CSkypeProto::LoadContactsInfo(const NETLIBHTTPREQUEST *response) { if (response == NULL) return; JSONNode root = JSONNode::parse(response->pData); if (!root) return; const JSONNode &items = root.as_array(); for (size_t i = 0; i < items.size(); i++) { const JSONNode &item = items.at(i); if (!item) break; std::string skypename = item["username"].as_string(); MCONTACT hContact = AddContact(skypename.c_str()); if (hContact) { UpdateProfileCountry(item, hContact); UpdateProfileCity(item, hContact); UpdateProfileStatusMessage(item, hContact); } } }
bool JSONReader::parseAll(const std::string& text, IdType& nextId, std::string& filepath, std::string& checksum, std::vector<std::shared_ptr<MetadataStream::VideoSegment>>& segments, std::vector<std::shared_ptr<MetadataSchema>>& schemas, std::vector<std::shared_ptr<MetadataInternal>>& metadata) { if(text.empty()) { VMF_LOG_ERROR("Empty input JSON string"); return false; } schemas.clear(); metadata.clear(); JSONNode root; try { root = libjson::parse(text); } catch(...) { VMF_LOG_ERROR("Can't get JSON root"); return false; } if(root.size() != 1) { VMF_LOG_ERROR("More than one JSON root"); return false; } JSONNode localRootNode = root[0]; if( localRootNode.name() == TAG_VMF ) { auto nextIdIter = localRootNode.find(ATTR_VMF_NEXTID); if(nextIdIter != localRootNode.end() ) nextId = nextIdIter->as_int(); auto filepathIter = localRootNode.find(ATTR_VMF_FILEPATH); if(filepathIter != localRootNode.end() ) filepath = filepathIter->as_string(); auto checksumIter = localRootNode.find(ATTR_VMF_CHECKSUM); if(checksumIter != localRootNode.end() ) checksum = checksumIter->as_string(); if(!parseVideoSegments(text, segments)) return false; if(!parseSchemas(text, schemas)) return false; if(!parseMetadata(text, schemas, metadata)) return false; } else { VMF_LOG_ERROR("Root JSON element isn't 'vmf'"); return false; } return true; }
void CDropbox::CommandShare(void *arg) { CommandParam *param = (CommandParam*)arg; char *path = (char*)param->data; if (path == NULL) { CMStringA error(FORMAT, T2Utf(TranslateT("\"%s\" command has invalid parameter.\nUse \"/help\" for more info.")), "/share"); ProtoBroadcastAck(MODULE, param->hContact, ACKTYPE_MESSAGE, ACKRESULT_SUCCESS, param->hProcess, 0); CallContactService(param->instance->GetDefaultContact(), PSR_MESSAGE, 0, (LPARAM)error.GetBuffer()); return; } ptrA token(db_get_sa(NULL, MODULE, "TokenSecret")); ptrA encodedPath(mir_utf8encode(path)); bool useShortUrl = db_get_b(NULL, MODULE, "UseSortLinks", 1) > 0; ShareRequest request(token, encodedPath, useShortUrl); NLHR_PTR response(request.Send(param->instance->hNetlibConnection)); if (response == NULL || response->resultCode != HTTP_STATUS_OK) { ProtoBroadcastAck(MODULE, param->hContact, ACKTYPE_MESSAGE, ACKRESULT_FAILED, param->hProcess, 0); return; } JSONNode root = JSONNode::parse(response->pData); if (root.empty()) { ProtoBroadcastAck(MODULE, param->hContact, ACKTYPE_MESSAGE, ACKRESULT_FAILED, param->hProcess, 0); return; } CMStringA link = root.at("url").as_string().c_str(); ProtoBroadcastAck(MODULE, param->hContact, ACKTYPE_MESSAGE, ACKRESULT_SUCCESS, param->hProcess, 0); CallContactService(param->instance->GetDefaultContact(), PSR_MESSAGE, 0, (LPARAM)link.GetBuffer()); }
void Callback(JSONNode & test, void * ide){ assertEquals(ide, (void*)0xDEADBEEF); ++counter; switch(counter){ case 1: assertEquals(test.type(), JSON_NODE); assertTrue(test.empty()); break; case 2: assertEquals(test.type(), JSON_ARRAY); assertTrue(test.empty()); break; case 3: assertEquals(test.type(), JSON_NODE); assertEquals(test.size(), 1); assertEquals(test[0].name(), JSON_TEXT("hello")); assertEquals(test[0].as_int(), 1); break; case 4: assertEquals(test.type(), JSON_ARRAY); assertEquals(test.size(), 3); break; case 5: assertEquals(test.type(), JSON_NODE); assertEquals(test.size(), 1); assertEquals(test[0].name(), JSON_TEXT("hi")); assertEquals(test[0].size(), 1) assertEquals(test[0][0].type(), JSON_NUMBER); assertEquals(test[0][0].name(), JSON_TEXT("one")); assertEquals(test[0][0].as_int(), 1); break; } }
/// we are always returning true unless the script /// itself is failing not the inquiry.. bool avtProgrammableOperation::avtVisItGetVarInfo::func(ProgrammableOpArguments& args, Variant& result) { std::string varName = args.getArg(0).AsString(); vtkDataSet* dataset = args.GetInputDataSet(); bool pointData = true; vtkDataArray* array = dataset->GetPointData()->GetScalars(varName.c_str()); if(!array) { array = dataset->GetCellData()->GetScalars(varName.c_str()); pointData = false; } /// for now just deal with scalars.. if(array == NULL) { result = ""; return true; } /// now extract information from the array.. /// through in mesh dimensions to help inquiring class reshape /// information correctly.. JSONNode resultNode; resultNode["type"] = pointData ? "pointdata" : "celldata"; JSONNode::JSONArray dims(3,-1); resultNode["dims"] = dims; result = resultNode.ToString(); return true; }
void CDropbox::CommandDelete(void *arg) { CommandParam *param = (CommandParam*)arg; char *path = (char*)param->data; if (path == NULL) { CMStringA error(FORMAT, T2Utf(TranslateT("\"%s\" command has invalid parameter.\nUse \"/help\" for more info.")), "/delete"); ProtoBroadcastAck(MODULE, param->hContact, ACKTYPE_MESSAGE, ACKRESULT_SUCCESS, param->hProcess, 0); CallContactService(param->instance->GetDefaultContact(), PSR_MESSAGE, 0, (LPARAM)error.GetBuffer()); return; } ptrA token(db_get_sa(NULL, MODULE, "TokenSecret")); ptrA encodedPath(mir_utf8encode(path)); DeleteRequest request(token, encodedPath); NLHR_PTR response(request.Send(param->instance->hNetlibConnection)); if (response == NULL || response->resultCode != HTTP_STATUS_OK) { ProtoBroadcastAck(MODULE, param->hContact, ACKTYPE_MESSAGE, ACKRESULT_FAILED, param->hProcess, 0); return; } JSONNode root = JSONNode::parse(response->pData); if (root.empty()) { ProtoBroadcastAck(MODULE, param->hContact, ACKTYPE_MESSAGE, ACKRESULT_FAILED, param->hProcess, 0); return; } bool isDeleted = root.at("is_deleted").as_bool(); CMStringA message(FORMAT, "%s %s", path, !isDeleted ? T2Utf(TranslateT("is not deleted")) : T2Utf(TranslateT("is deleted"))); ProtoBroadcastAck(MODULE, param->hContact, ACKTYPE_MESSAGE, ACKRESULT_SUCCESS, param->hProcess, 0); CallContactService(param->instance->GetDefaultContact(), PSR_MESSAGE, 0, (LPARAM)message.GetBuffer()); }
void test_profile_view(){ HTTPClientSession s(HOST, PORT); HTTPRequest request(HTTPRequest::HTTP_GET, std::string("/api/v1/profile/").append(created_profile_uuid)); s.sendRequest(request); HTTPResponse response; std::istream& rs = s.receiveResponse(response); std::string data; StreamCopier::copyToString(rs, data); LOGDEBUG("response:"<<data); JSONNode node = getJson(data); assert_response(node); assert(node.contains("data")); assert(node["data"].contains("format")); assert(node["data"]["format"].contains("id")); assert(node["data"]["format"]["id"]=="matroska"); assert(node["data"].contains("video")); assert(node["data"]["video"].contains("id")); assert(node["data"]["video"]["id"]=="mpeg4"); assert(node["data"].contains("audio")); }
void SharedDaemon::AddNewClient(const std::string &host, const stringVector &args, void *cbdata) { /// Send appropriate message for TCP or WebConnection void** data = (void**)cbdata; ConnectionType typeOfConnection = *((ConnectionType*)(data[0])); QAbstractSocket* socket = static_cast<QAbstractSocket*>(data[1]); ViewerState* viewerState = static_cast<ViewerState*>(data[2]); JSONNode node; QString hostname = typeOfConnection == TcpConnection ? socket->localAddress().toString(): dynamic_cast<QWsSocket*>(socket)->internalSocket()->localAddress().toString(); if(hostMap.contains(hostname)) hostname = hostMap[hostname]; node["host"] = hostname.toStdString(); //host node["port"] = args[7]; //port node["version"] = args[2]; //version node["securityKey"] = args[9]; //key node["numStates"] = viewerState->GetNumStateObjects(); //number of states JSONNode::JSONArray rpc_array = JSONNode::JSONArray(); for(size_t i = 0; i < ViewerRPC::MaxRPC; ++i) { rpc_array.push_back(ViewerRPC::ViewerRPCType_ToString((ViewerRPC::ViewerRPCType)i)); } node["rpc_array"] = rpc_array; if(typeOfConnection == TcpConnection) { QTcpSocket *tsocket = dynamic_cast<QTcpSocket*>(socket); std::string message = node.ToString(); tsocket->write(message.c_str(),message.length()); if(tsocket->state() != QAbstractSocket::UnconnectedState) tsocket->waitForBytesWritten(); tsocket->disconnectFromHost(); if(tsocket->state() != QAbstractSocket::UnconnectedState) tsocket->waitForDisconnected(); //HKTODO: Do not delete connection (test fix for ORNL machines) //tsocket->deleteLater(); } else { QWsSocket *wsocket = dynamic_cast<QWsSocket*>(socket); wsocket->write(QString(node.ToString().c_str())); wsocket->flush(); if(wsocket->internalSocket()->state() != QAbstractSocket::UnconnectedState) wsocket->internalSocket()->waitForBytesWritten(); wsocket->close(""); wsocket->internalSocket()->disconnectFromHost(); if(wsocket->internalSocket()->state() != QAbstractSocket::UnconnectedState) wsocket->internalSocket()->waitForDisconnected(); wsocket->deleteLater(); } }
void write_formatted(JSONNode n, const char *filename){ if(n.type()!=JSON_NULL){ std::string jc = n.write_formatted(); std::ofstream out(filename); out << jc; out.close(); } }
JSONNode Event::toJSON() { // this is equivalent to saying "something happened here but I have no idea what it is" JSONNode e; e.set_name(_id); e.push_back(JSONNode("type", getType())); return e; }
// **************************************************************************** // Method: SocketConnection::Flush // // Purpose: // Writes the entire contents of the connection's buffer onto the // socket file descriptor in chunks. It then clears the buffer. // // // Programmer: Brad Whitlock // Creation: Tue Aug 29 12:17:37 PDT 2000 // // Modifications: // Brad Whitlock, Tue Mar 26 13:29:20 PST 2002 // Made it use socket functions so it is more portable. // // Brad Whitlock, Thu Jan 25 18:42:50 PST 2007 // I made it use MSG_NOSIGNAL so we don't get a signal in the event that // we can't write to the socket. // // Eric Brugger, Tue Mar 13 09:18:48 PDT 2007 // I made the use of MSG_NOSIGNAL conditional on its definition. // // **************************************************************************** void SocketConnection::Flush(AttributeSubject *subject) { if(destFormat.Format == TypeRepresentation::BINARYFORMAT) Connection::Flush(subject); else { // std::cout << subject->TypeName() << " " // << subject->CalculateMessageSize(*this) // << std::endl; if(subject->GetSendMetaInformation()) { MapNode meta; JSONNode node; subject->WriteMeta(meta); node["id"] = subject->GetGuido(); node["typename"] = subject->TypeName(); node["api"] = meta.ToJSONNode(false,false); const std::string& output = node.ToString().c_str(); #if defined(_WIN32) send(descriptor, (const char FAR *)output.c_str(), output.size(), 0); #else #ifdef MSG_NOSIGNAL send(descriptor, (const void *)output.c_str(), output.size(), MSG_NOSIGNAL); #else send(descriptor, (const void *)output.c_str(), output.size(), 0); #endif #endif } MapNode child; JSONNode node; subject->Write(child); node["id"] = subject->GetGuido(); node["typename"] = subject->TypeName(); node["contents"] = child.ToJSONNode(false); const std::string& output = node.ToString(); #if defined(_WIN32) send(descriptor, (const char FAR *)output.c_str(), output.size(), 0); #else #ifdef MSG_NOSIGNAL send(descriptor, (const void *)output.c_str(), output.size(), MSG_NOSIGNAL); #else send(descriptor, (const void *)output.c_str(), output.size(), 0); #endif #endif buffer.clear(); } }
static void readIntVector(const JSONNode& nd, int vecsz, int * x) { int k = 0; for (auto i = nd.begin(); i != nd.end(); i++) { int u = i->as_int(); BNB_ASSERT(k < vecsz); x[k++] = u; } BNB_ASSERT(k == vecsz); }
bool CPPModule::init(const std::string& jsonParams) { JSONNode n = libjson::parse(jsonParams); std::map<std::string, std::string> tmpParams; JSONNode::iterator i = n.begin(); for(; i!=n.end(); ++i) { tmpParams[(*i).name()] = (*i).as_string(); } return onInit(tmpParams); }
static void readDoubleVector(const JSONNode& nd, int vecsz, double * x) { int k = 0; for (auto i = nd.begin(); i != nd.end(); i++) { double u = i->as_float(); BNB_ASSERT(k < vecsz); x[k++] = u; } BNB_ASSERT(k == vecsz); }
JSONNode JSONNode::stringType(const json_string & str){ JSONNode res; res.set_name(json_global(EMPTY_JSON_STRING)); #ifdef JSON_LESS_MEMORY res = JSONWorker::FixString(str, res.internal, false); #else res = JSONWorker::FixString(str, res.internal -> _string_encoded); #endif return res; }
JSONNode JSONNodeHelper::findKey(JSONNode jsonNode, std::string key) { JSONNode returnNode; for (JSONNode::const_iterator i = jsonNode.begin(); i != jsonNode.end(); i++){ if (i->name() == key){ returnNode = *i; } } // TODO: throw exception if the key is not found return returnNode; }
MEVENT CSkypeProto::AppendDBEvent(MCONTACT hContact, MEVENT hEvent, const char *szContent, const char *szUid, time_t edit_time) { mir_cslock lck(m_AppendMessageLock); DBEVENTINFO dbei = { sizeof(dbei) }; dbei.cbBlob = db_event_getBlobSize(hEvent); dbei.pBlob = mir_ptr<BYTE>((PBYTE)mir_alloc(dbei.cbBlob)); db_event_get(hEvent, &dbei); JSONNode jMsg = JSONNode::parse((char*)dbei.pBlob); if (jMsg) { JSONNode &jEdits = jMsg["edits"]; if (jEdits) { for (auto it = jEdits.begin(); it != jEdits.end(); ++it) { const JSONNode &jEdit = *it; if (jEdit["time"].as_int() == edit_time) return hEvent; } JSONNode jEdit; jEdit << JSONNode("time", (long)edit_time) << JSONNode("text", szContent); jEdits << jEdit; } } else { jMsg = JSONNode(); JSONNode jOriginalMsg; jOriginalMsg.set_name("original_message"); JSONNode jEdits(JSON_ARRAY); jEdits.set_name("edits"); JSONNode jEdit; jOriginalMsg << JSONNode("time", (long)dbei.timestamp) << JSONNode("text", (char*)dbei.pBlob); jMsg << jOriginalMsg; jEdit << JSONNode("time", (long)edit_time) << JSONNode("text", szContent); jEdits << jEdit; jMsg << jEdits; } db_event_delete(hContact, hEvent); return AddDbEvent(SKYPE_DB_EVENT_TYPE_EDITED_MESSAGE, hContact, dbei.timestamp, DBEF_UTF, jMsg.write().c_str(), szUid); }
void test_profile_create(){ HTTPClientSession s(HOST, PORT); HTTPRequest request(HTTPRequest::HTTP_POST, "/api/v1/profile/"); //std::ostringstream os; JSONNode base(JSON_NODE); base.push_back(JSONNode("name","test profile")); base.push_back(JSONNode("description","test description")); JSONNode format(JSON_NODE); format.set_name("format"); format.push_back(JSONNode("id","mp4")); base.push_back(format); JSONNode video(JSON_NODE); video.set_name("video"); //video.push_back(JSONNode("id","mpeg4")); video.push_back(JSONNode("id","libx264")); video.push_back(JSONNode("qscale","4")); video.push_back(JSONNode("aubq","8")); video.push_back(JSONNode("me_range","16")); video.push_back(JSONNode("qmin","4")); video.push_back(JSONNode("qmax","51")); video.push_back(JSONNode("qcomp","0.6")); video.push_back(JSONNode("qdiff","4")); base.push_back(video); JSONNode audio(JSON_NODE); audio.set_name("audio"); audio.push_back(JSONNode("id","mp2")); audio.push_back(JSONNode("ar","44100")); audio.push_back(JSONNode("ac","2")); base.push_back(audio); //request.write(os); std::ostream & os=s.sendRequest(request); os << base.write_formatted(); HTTPResponse response; std::istream& rs = s.receiveResponse(response); std::string data; StreamCopier::copyToString(rs, data); LOGDEBUG("response:"<<data); JSONNode node = getJson(data); assert_response(node); assert(node.contains("uuid")); created_profile_uuid=node["uuid"].as_string(); }
static void processBox(const JSONNode & nd, Box<double> & box) { int n = box.mDim; for (auto i = nd.begin(); i != nd.end(); i++) { if (i->name() == JsonNames::boxa) { readDoubleVector(*i, n, (double*) (box.mA)); } else if (i->name() == JsonNames::boxb) { readDoubleVector(*i, n, (double*) (box.mB)); } else { BNB_ERROR_REPORT("Unknown name while processing box description"); } } }
static void processLattice(const JSONNode & nd, int n, double& v, double* x) { for (auto i = nd.begin(); i != nd.end(); i++) { if (i->name() == JsonNames::evalue) { v = i->as_float(); } else if (i->name() == JsonNames::lvector) { readDoubleVector(*i, n, x); } else { BNB_ERROR_REPORT("Unknown name while processing lattice description"); } } }
bool GameMapEncounterAreaParser::Parse(std::string json, GameMapEncounterArea *encounterArea) { JSONNode assetListNode = libjson::parse(json); JSONNode::const_iterator i = assetListNode.begin(); while (i != assetListNode.end()) { if (i->name() == "mobs" && i->type() == JSON_ARRAY) { this->logger->debug() << "parsing mobs"; JSONNode::const_iterator j = i->begin(); while (j != i->end()) { if (j->type() == JSON_NODE) { JSONNode::const_iterator k = j->begin(); while (k != j->end()) { if (k->name() == "enemies") { this->logger->debug() << "parsing enemies for mob"; JSONNode::const_iterator l = k->begin(); std::string r = ""; std::vector<std::string> mob; while (l != k->end()) { this->logger->debug() << std::setfill ('0') << std::setw(sizeof(unsigned char)*2) << std::hex << l->type(); if (l->type() == JSON_STRING) { r += l->as_string() + ", "; mob.push_back(l->as_string()); } l++; } this->logger->debug() << "parsed mob [" << r << "]"; encounterArea->mobs.push_back(mob); } k++; } } j++; } } i++; } return true; }