JSON parser tip in C

testspace

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.

What I want to do in C

enter image description here

testspace

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] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

분류에서Dev

Plug.Parser not reading/parsing JSON body

분류에서Dev

Apache Spark Object not Serializable Exception for json parser

분류에서Dev

Link C Flex lexer to C++ parser

분류에서Dev

Generic Parser that outputs code in C#

분류에서Dev

Parsing nested JSON using body-parser and express

분류에서Dev

JSON.parser없이 파서 만들기

분류에서Dev

json_parser 종속성 향상

분류에서Dev

Loop in Tip Calculator (Python)

분류에서Dev

Java tip calculator

분류에서Dev

objective-c json parser : 대괄호가 아닌 문자열로 시작하는 json 파일을 구문 분석하는 방법은 무엇입니까?

분류에서Dev

iOS 용 Easy XML-Parser-Objective C

분류에서Dev

c# CommandLine.Parser - Use constructor that accepts Action<ParserSettings>

분류에서Dev

Gumbo parser in C++ Builder XE6

분류에서Dev

body-parser bodyParser.json ()을 사용할 때 빈 json

분류에서Dev

Как предотвратить инициализацию свойств, которых нет в строке JSON во время десериализации в C #?

분류에서Dev

body-parser json 포스트 데이터 읽기 node.js express

분류에서Dev

xml parser : parser foundCharacters error

분류에서Dev

jquery Tool tip for svg element path

분류에서Dev

<boost \ property_tree \ json_parser.hpp> 링크를 시도 할 때 컴파일 오류

분류에서Dev

omegastripes / VBA-JSON-parser를 사용하여 "복잡한"구조로 json 구문 분석

분류에서Dev

omegastripes / VBA-JSON-parser를 사용하여 "복잡한"구조로 json 구문 분석

분류에서Dev

JSON 객체를 매퍼의 입력 값으로 읽는 동안 "java.lang.ClassNotFoundException : org.json.simple.parser.ParseException"발생

분류에서Dev

JSON 객체를 매퍼의 입력 값으로 읽는 동안 "java.lang.ClassNotFoundException : org.json.simple.parser.ParseException"발생

분류에서Dev

Java Rest Web Service에서 잘못된 JSON 데이터 오류를 처리하는 방법 : Jackson JSON Parser Unrecognized token

분류에서Dev

C# JSON & Parsing

분류에서Dev

D3-tip behind graph when in modal

분류에서Dev

Which is a faster parser for XML?

분류에서Dev

Using `err` in a Child Parser

분류에서Dev

Using `err` in a Child Parser

Related 관련 기사

  1. 1

    Plug.Parser not reading/parsing JSON body

  2. 2

    Apache Spark Object not Serializable Exception for json parser

  3. 3

    Link C Flex lexer to C++ parser

  4. 4

    Generic Parser that outputs code in C#

  5. 5

    Parsing nested JSON using body-parser and express

  6. 6

    JSON.parser없이 파서 만들기

  7. 7

    json_parser 종속성 향상

  8. 8

    Loop in Tip Calculator (Python)

  9. 9

    Java tip calculator

  10. 10

    objective-c json parser : 대괄호가 아닌 문자열로 시작하는 json 파일을 구문 분석하는 방법은 무엇입니까?

  11. 11

    iOS 용 Easy XML-Parser-Objective C

  12. 12

    c# CommandLine.Parser - Use constructor that accepts Action<ParserSettings>

  13. 13

    Gumbo parser in C++ Builder XE6

  14. 14

    body-parser bodyParser.json ()을 사용할 때 빈 json

  15. 15

    Как предотвратить инициализацию свойств, которых нет в строке JSON во время десериализации в C #?

  16. 16

    body-parser json 포스트 데이터 읽기 node.js express

  17. 17

    xml parser : parser foundCharacters error

  18. 18

    jquery Tool tip for svg element path

  19. 19

    <boost \ property_tree \ json_parser.hpp> 링크를 시도 할 때 컴파일 오류

  20. 20

    omegastripes / VBA-JSON-parser를 사용하여 "복잡한"구조로 json 구문 분석

  21. 21

    omegastripes / VBA-JSON-parser를 사용하여 "복잡한"구조로 json 구문 분석

  22. 22

    JSON 객체를 매퍼의 입력 값으로 읽는 동안 "java.lang.ClassNotFoundException : org.json.simple.parser.ParseException"발생

  23. 23

    JSON 객체를 매퍼의 입력 값으로 읽는 동안 "java.lang.ClassNotFoundException : org.json.simple.parser.ParseException"발생

  24. 24

    Java Rest Web Service에서 잘못된 JSON 데이터 오류를 처리하는 방법 : Jackson JSON Parser Unrecognized token

  25. 25

    C# JSON & Parsing

  26. 26

    D3-tip behind graph when in modal

  27. 27

    Which is a faster parser for XML?

  28. 28

    Using `err` in a Child Parser

  29. 29

    Using `err` in a Child Parser

뜨겁다태그

보관