/** * @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 ""; }
/** * @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; }
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]; } } } }