/** * @return The integer value of a field at the top-level * of the JSON tree. Return 0 if the field does not exist. */ int PhoneGapMessage::getArgsFieldInt(const MAUtil::String& fieldName) { if (NULL != mJSONRoot) { YAJLDom::Value* value = mJSONRoot->getValueForKey(fieldName.c_str()); if (NULL != value && YAJLDom::Value::NUMBER == value->getType()) { return value->toInt(); } } return 0; }
/** * @return The string value of a field at the top-level * of the JSON tree. Return empty string if the field * does not exist. */ MAUtil::String PhoneGapMessage::getArgsField(const MAUtil::String& fieldName) { if (NULL != mJSONRoot) { YAJLDom::Value* value = mJSONRoot->getValueForKey(fieldName.c_str()); if (NULL != value && YAJLDom::Value::STRING == value->getType()) { return value->toString(); } } return ""; }
void CBGeoDataStream::parseResponse(Cloudbase::CBHelperResponseInfo resp) { if (resp.postSuccess) { if (resp.parsedMessage->getType() == YAJLDom::Value::ARRAY) { for (int i = 0; i < resp.parsedMessage->getNumChildValues(); i++) { YAJLDom::Value* newObj = resp.parsedMessage->getValueByIndex(i); CBGeoLocatedObject* outputObj = new CBGeoLocatedObject(); YAJLDom::Value* location = newObj->getValueForKey("cb_location"); double lat = location->getValueForKey("lat")->toDouble(); double lng = location->getValueForKey("lng")->toDouble(); if (!newObj->getValueForKey("cb_location_altitude")->isNull()) { double altitude = newObj->getValueForKey("cb_location_altitude")->toDouble(); outputObj->coordinate = QtMobilitySubset::QGeoCoordinate(lat, lng, altitude); outputObj->altitude = altitude; } else { outputObj->coordinate = QtMobilitySubset::QGeoCoordinate(lat, lng); } outputObj->objectData = newObj; this->foundObjects.insert(std::make_pair(outputObj->hash(), outputObj)); emit receivedPoint(outputObj, this->streamName); } } } else { qDebug("Error while calling the cloudbase.io APIs: %s", resp.errorMessage.c_str()); } }
void CBHttpConnection::parseResponseOutput(int statusCode, String function, CBHelperResponder* responder) { CBHelperResponseInfo resp; resp.httpStatusCode = statusCode; resp.function = function; resp.outputString = mBuffer; //printf("buffer size: %i", sizeof(mBuffer)); //printf("received response: %s:", mBuffer); YAJLDom::Value* root = YAJLDom::parse( (const unsigned char*)mBuffer, sizeof(mBuffer)); if (NULL == root || YAJLDom::Value::NUL == root->getType()) { printf("no tree"); resp.errorMessage = "Error while parsing JSON response"; } else { YAJLDom::Value* functionData = root->getValueForKey(function); //printf("got the tree for the function"); if (NULL == functionData || YAJLDom::Value::MAP != functionData->getType()) { printf("error getting function data"); resp.errorMessage = "Could not find function data in response"; } else { //printf("total child %i", functionData->getNumChildValues()); //printf(functionData->toString().c_str()); resp.postSuccess = (functionData->getValueForKey("status")->toString() == "OK"); resp.errorMessage = functionData->getValueForKey("error")->toString(); if (NULL != responder) { //printf("have responder"); responder->parseResponse(resp, functionData->getValueForKey("message")); } } // TODO: we should probably clean up the YAJLDom object here - Unfortunately there is an issue // when the responder tries to use it as it would have been already closed } }
/** * \brief parseJSON * \note parses from mSharedData and populate the arrays such as * mNameTable[], mTable[], mDataTime, mColor[] */ void parseJSON() { YAJLDom::Value *jsonRoot = YAJLDom::parse((const unsigned char*)mSharesData, strlen(mSharesData)); if(jsonRoot->getType() == YAJLDom::Value::ARRAY) { lprintfln("SUCCESS IN PARSING JSON DATA"); MAUtil::String tmp,t; float scale = mScaleBarHeight; const int gridX = mGraph->getScene().getGridX(); const int gridZ = mGraph->getScene().getGridZ(); bool bGotDate = false; for(int i=0; i<gridX; i++) { YAJLDom::Value *row = jsonRoot->getValueByIndex(i); int j = 0; t = row->getValueForKey("t")->toString(); mNameTable[i + gridX*j] = t.c_str(); tmp = row->getValueForKey("l")->toString(); mTables[i + gridX*j] = scale*(atof(tmp.c_str())); lprintfln("@@@r l=%s t=%s", tmp.c_str(),t.c_str()); j++; t = row->getValueForKey("t")->toString(); mNameTable[i + gridX*j] = t.c_str(); tmp = row->getValueForKey("l_cur")->toString(); mTables[i + gridX*j] = scale*(atof(tmp.c_str())); lprintfln("@@@ l_cur=%s t=%s", tmp.c_str(),t.c_str()); j++; t = row->getValueForKey("t")->toString(); mNameTable[i + gridX*j] = t.c_str(); tmp = row->getValueForKey("c")->toString(); mTables[i + gridX*j] = scale*(atof(tmp.c_str())); lprintfln("@@@ c=%s t=%s", tmp.c_str(),t.c_str()); j++; t = row->getValueForKey("t")->toString(); mNameTable[i + gridX*j] = t.c_str(); tmp = row->getValueForKey("cp")->toString(); mTables[i + gridX*j] = scale*(atof(tmp.c_str())); lprintfln("@@@ cp=%s t=%s", tmp.c_str(),t.c_str()); if (bGotDate == false) { tmp = row->getValueForKey("lt")->toString(); mDateTime = tmp.c_str(); bGotDate = true; } } glm::vec4 colScheme[gridZ]; glm::vec4 redScheme[gridZ]; colScheme[0] = glm::vec4(0.0f, 236.0f/255.0f, 255.0f/255.0f, 1.0f); // L blue colScheme[1] = glm::vec4(0.0f, 177.0f/255.0f, 191.0f/255.0f, 1.0f); // D blue colScheme[2] = glm::vec4(181.0f/255.0f, 255.0f/255.0f, 0.0f, 1.0f); // L Green colScheme[3] = glm::vec4(124.0f/255.0f, 175.0f/255.0f, 0.0f, 1.0f); // D Green redScheme[0] = glm::vec4(255.0f/255.0f, 0.0f, 236.0f/255.0f, 1.0f); // L blue redScheme[1] = glm::vec4(177.0f/255.0f, 0.0f, 191.0f/255.0f, 1.0f); // D blue redScheme[2] = glm::vec4(255.0f/255.0f, 90.0f/255.0f, 0.0f, 1.0f); // L Red redScheme[3] = glm::vec4(175.0f/255.0f, 64.0f/255.0f, 0.0f, 1.0f); // D Red for(int j=0; j<gridZ; j++) { for(int i=0; i<gridX; i++) { const int id = i+gridX*j; mColors[id] = mTables[id]>=0.0f? colScheme[j]: redScheme[j]; } } } }
void PhotoLoader::parseResponse(Cloudbase::CBHelperResponseInfo resp) { if ( resp.function == "download" ) { qDebug() << "received file"; QString oldName = QString::fromStdString(resp.downloadedFileName); QString newName = QString::fromStdString(resp.downloadedFileName+".jpg"); QFile::rename(oldName, newName); qDebug() << QString::fromStdString(resp.downloadedFileName); return; } qDebug() << "error message: " << resp.errorMessage.c_str(); if ( resp.postSuccess ) { if ( resp.parsedMessage->getType() == YAJLDom::Value::ARRAY ) { QVariantList photos; // loop over the array of objects from the photos collection for (int i = 0; i < resp.parsedMessage->getNumChildValues(); i++) { YAJLDom::Value* curPhoto = resp.parsedMessage->getValueByIndex(i); // get all the basic data for the current object QString title = QString::fromStdString(curPhoto->getValueForKey("title")->toString()); QString username = QString::fromStdString(curPhoto->getValueForKey("username")->toString()); QString tags = QString::fromStdString(curPhoto->getValueForKey("tags")->toString()); QString photoTime = QString::fromStdString(curPhoto->getValueForKey("photo_time")->toString()); QString filePath = ""; Photo* newPhoto = new Photo(title, username, tags, ""); // if we have files attached to the document if (!curPhoto->getValueForKey("cb_files")->isNull()) { YAJLDom::Value* photoFiles = curPhoto->getValueForKey("cb_files"); // loop over the files - we may have multiple files as we could be creating // thumbnails as well as the full size picture. We assume the thumbnail images // contain "thumb" in the file name for (int y = 0; y < photoFiles->getNumChildValues(); y++) { qDebug() << "loop over files"; YAJLDom::Value* curFile = photoFiles->getValueByIndex(y); qDebug() << "starting download"; const QDir home = QDir::currentPath()+"/data/"; QString fileIdString = QString::fromStdString(curFile->getValueForKey("file_id")->toString()); filePath = home.absoluteFilePath(fileIdString); newPhoto->setThumbnailFileId(filePath); helper->downloadFile(curFile->getValueForKey("file_id")->toString(), this); qDebug() << "file path: " << filePath; } // send the photo back to the application using the SIGNAL //emit receivedPhoto(newPhoto); } else { qDebug() << "no files"; } QVariantMap photoMap; qDebug() << "loaded photo: " << title; photoMap["title"] = title; photoMap["imageSource"] = filePath; photoMap["username"] = username; photoMap["tags"] = tags; photoMap["time"] = photoTime; //photos.append(photoMap); photos << photoMap; } qDebug() << "Emitting signal receivedPhotos"; emit receivedPhotos(photos); } } }