first of all i know there are lots of lists out there and over the last 3 days i probably checked out 10+ free json-parsers. The reason I am still looking is probably because I didn't find working examples / infos / whatnot to get what i want working quite simply. I'm quite sure that this will end up being reported as reask but nevertheless i beg for someone with JSON in C expierence to give me a quick tip since this would probably safe me hours of googling and looking into an API where i need about 10 lines of code or something.
The data is passed as a string delimered with a ','
JSON Data (Array)
string, string, int (Array)
Username,Password,2.4.0
Basically all i need is an api which offers something similar as
[SWF] JSON->Stringify();
["Username","Password","2.4.0"]
Sorry if you consider that an annoying repost but thanks for reading anyway.
Ended up with something like this. Just posting in case someone comes across something similar. Anyway I ended up using frozen JSON parser for parsing and json-parser for validating.
BOOL IsNumber(const char *string)
{
char *pch;
pch = string;
while (*pch != '\0')
{
if (!isdigit(*pch)) return FALSE;
pch++;
}
return TRUE;
}
char* test(const char *Data)
{
char *retVal = NULL;
char *buffer;
char *ptr;
int len;
buffer = (char*)malloc(strlen(Data) + 1);
strcpy(buffer, Data);
ptr = strtok(buffer, ",");
if (ptr)
{
len = 2;
retVal = (char*)malloc(2);
strcpy(retVal, "[");
do
{
len += strlen(ptr) + 1;
if (IsNumber(ptr))
{
retVal = (char*)realloc(retVal, len);
sprintf(retVal, "%s%s,", retVal, ptr);
}
else
{
len += 2;
retVal = (char*)realloc(retVal, len);
sprintf(retVal, "%s\"%s\",", retVal, ptr);
}
ptr = strtok(NULL, ",");
}
while (ptr != NULL);
retVal[len - 2] = ']';
}
free(buffer);
return retVal;
}
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다