Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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...

 log("%s",concatenated);

...it outputs data like this:

 id:mtpass:thkr

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

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

share|improve this question
    
Hey did you find an answer to this? – ctapp1 Nov 5 '15 at 17:05

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.