Valid json check in C language

帅比萌擦擦* 提交于 2020-05-28 11:56:21

问题


I have searched a lot in Google. I want to programmatically check if the string below is valid JSON in C. How can I do that? (I am currently using the json-c library.)

        char * string = "{
                      number1 : 100,
                    number2 : 10,
                    files : [ c , c++, java,PHP,java,PHP ],
                    random: [123567876523333,908,988]
                    }";

The library has no function to check if the string is valid JSON.


回答1:


You can use the function json_tokener_parse(const char *str), it returns NULL if parsing fails.

See here for details.



来源:https://stackoverflow.com/questions/37773273/valid-json-check-in-c-language

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!