Skip to content

Instantly share code, notes, and snippets.

@taoso
Last active August 29, 2015 13:57
Show Gist options
  • Save taoso/9382894 to your computer and use it in GitHub Desktop.
Save taoso/9382894 to your computer and use it in GitHub Desktop.
cJSON解析字符串
#include <stdio.h>
#include <stdlib.h>
#include "cJSON.h"
void doit(char *text)
{
char *out;cJSON *json;
json=cJSON_Parse(text);
if (!json) {printf("Error before: [%s]\n",cJSON_GetErrorPtr());}
else
{
//out=cJSON_Print(json);
out = cJSON_PrintUnformatted(json);
cJSON_Delete(json);
printf("%s\n",out);
free(out);
}
}
int main (int argc, const char * argv[]) {
char hehe[]="{\"mid\":5,\"lpt\":1,\"pv\":\"1.0\",\"option\":2,\"cs\":{\"mid\":1005,\"index\":0,\"count\":10}}\n\r";
doit(hehe);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment