Last active
August 29, 2015 13:57
-
-
Save taoso/9382894 to your computer and use it in GitHub Desktop.
cJSON解析字符串
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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