I am making a HTTP request to a server and I am getting data from the database. Now I want to parse the 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 an 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...


...it outputs data like this:


Reference - https://gist.github.com/Tetz/81686772

So how to get the data in variables id and pass?

  • \$\begingroup\$ Hey did you find an answer to this? \$\endgroup\$ – ctapp1 Nov 5 '15 at 17:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.