Hello,
I make a GET request to server and receive the data, and i can print it like this :
for (unsigned int i = 0; i < buffer->size(); i++)
{
log("%c", (*buffer)[i]);
}
json returns id and pass, so how to load this id and pass into different variables for later use…
I am trying to parse json data and get the data into variables like this :
std::vector<char> * buffer = response->getResponseData();
char * concatenated = (char *) malloc(buffer->size() + 1);
std::string s2(buffer->begin(), buffer->end());
strcpy(concatenated, s2.c_str());
Json * json = Json_create(concatenated);
std::string test1 = Json_getString(json, "id", "default");
std::string test2 = Json_getString(json, "pass", "default");
CCLog("HTTP Response : id : %s", test1);
CCLog("HTTP Response : pass : %s", test2);
but i am getting error on :
Json *Json_getItem (Json *object, const char* string) {
Json *c = object->child; error on this line -- exc_bad_access
while (c && Json_strcasecmp(c->name, string))
c = c->next;
return c;
}
when i log -
log("%s",concatenated);
it outputs data like this -
id:mtpass:thkr
reference - https://gist.github.com/Tetz/8168677
plz help…
Try looking into rapidjson instead, it’s bundled with cocos2d-x.
This WORKS FOR UPDATED == > 3.1x