what is the best way to parse JSON object we get from API response and remove it so it won’t live in RAM
we are doing like this, do I need to do any suggestion please cz, me really having problem with memory
void TitleScene::sendApplicantJoinClub(std::string clubToJoin, std::string Verificationinfo){
httpRequestNumber += 1;
log("httpRequestNumber : %d \n",httpRequestNumber);
rapidjson::Document d;
d.SetObject();
rapidjson::Document::AllocatorType& allocator = d.GetAllocator();
d.AddMember("name", rapidjson::Value(clubToJoin.c_str() , allocator) ,d.GetAllocator()) ;
d.AddMember("verification_info", rapidjson::Value(Verificationinfo.c_str() , allocator) ,d.GetAllocator()) ;
// Convert JSON document to string
rapidjson::StringBuffer strbuf;
rapidjson::PrettyWriter<rapidjson::StringBuffer> writer(strbuf);
d.Accept(writer);
auto request = new (std :: nothrow) cocos2d::network::HttpRequest();
request->setUrl(SendApplicantJoinClubURL);
request->setRequestType(cocos2d::network::HttpRequest::Type::POST);
request->setResponseCallback(CC_CALLBACK_2 (TitleScene::sendApplicantJoinClubAPIResponse, this));
std::vector<std::string> headers;
headers.emplace_back(CONTENT_TYPE);
headers.emplace_back(X_AUTO_TOKEN);
request->setHeaders(headers);
request->setRequestData(strbuf.GetString(), strbuf.GetSize());
cocos2d::network::HttpClient::getInstance()->sendImmediate(request);
request->release();
}
void TitleScene::sendApplicantJoinClubAPIResponse(cocos2d::network::HttpClient *sender, cocos2d::network::HttpResponse *response){
httpRequestNumber -= 1;
log("httpRequestNumber : %d \n",httpRequestNumber);
std::string err;
if(!response->isSucceed()){
log("Respond Failed getClubListAPIResponse\n");
return;
}
//Json made
std::vector<char> *buffer = response->getResponseData();
char *json = (char *) malloc(buffer->size() + 1);
std::string s2(buffer->begin(), buffer->end());
strcpy(json, s2.c_str());
CCASSERT(err.empty(), err.c_str());
/////////////////////////////////////////////////////////////////////
// Need Document object
rapidjson::Document jsonDoc;
// data is like string above
jsonDoc.Parse(json);
// parse Status
bool Status = jsonDoc["isValid"].GetBool();
// parse RespondCode
int RespondCode = jsonDoc["code"].GetInt();
if (Status && RespondCode==200) {
log("Succeeded in Join club : %ld\n", response->getResponseCode());
getClubList();
return;
}else{
const char * ErrorMessage = jsonDoc["message"].GetString();
log(" ErrorMessage : %s \n ResponceCode : %d \n",ErrorMessage,RespondCode);
}
}