You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
parson/params.json

1 line
3.0 KiB

{"body":"##About\r\nParson is a small [json](http://json.org) parser and reader written in C. \r\n\r\n##Features\r\n* Small (only 2 files)\r\n* Simple API\r\n* Addressing json values with dot notation (similiar to C structs or objects in most OO languages, e.g. \"objectA.objectB.value\")\r\n* C89 compatible\r\n* Test suites\r\n\r\n##Installation\r\nRun the following code:\r\n```\r\ngit clone https://github.com/kgabis/parson.git\r\n```\r\nand copy parson.h and parson.c to you source code tree.\r\n\r\n##Example\r\nHere is a function, which prints basic commit info (date, sha and author) from a github repository. It's also included in tests.c file, you can just uncomment and run it.\r\n```c\r\nvoid print_commit_info(const char *username, const char * repo) {\r\n JSON_Value *root_value;\r\n JSON_Array *commits;\r\n JSON_Object *commit;\r\n int i;\r\n \r\n char curl_command[512];\r\n char cleanup_command[256];\r\n char *output_filename = \"commits.json\";\r\n \r\n /* it ain't pretty, but it's not a libcurl tutorial */\r\n sprintf(curl_command, \"curl \\\"https://api.github.com/repos/%s/%s/commits\\\"\\\r\n > %s 2> /dev/null\", username, repo, output_filename);\r\n sprintf(cleanup_command, \"rm -f %s\", output_filename);\r\n system(curl_command);\r\n \r\n /* parsing json and validating output */\r\n root_value = json_parse_file(output_filename); \r\n if (root_value == NULL || json_value_get_type(root_value) != JSONArray) { \r\n system(cleanup_command);\r\n return;\r\n }\r\n \r\n /* getting array from root value and printing commit info */\r\n commits = json_value_get_array(root_value);\r\n printf(\"%-10.10s %-10.10s %s\\n\", \"Date\", \"SHA\", \"Author\");\r\n for (i = 0; i < json_array_get_count(commits); i++) {\r\n commit = json_array_get_object(commits, i);\r\n printf(\"%.10s %.10s %s\\n\",\r\n json_object_dotget_string(commit, \"commit.author.date\"),\r\n json_object_get_string(commit, \"sha\"),\r\n json_object_dotget_string(commit, \"commit.author.name\"));\r\n }\r\n \r\n /* cleanup code */\r\n json_value_free(root_value);\r\n system(cleanup_command);\r\n}\r\n```\r\nCalling ```print_commit_info(\"torvalds\", \"linux\");``` prints: \r\n```\r\nDate SHA Author\r\n2012-10-15 dd8e8c4a2c David Rientjes\r\n2012-10-15 3ce9e53e78 Michal Marek\r\n2012-10-14 29bb4cc5e0 Randy Dunlap\r\n2012-10-15 325adeb55e Ralf Baechle\r\n2012-10-14 68687c842c Russell King\r\n2012-10-14 ddffeb8c4d Linus Torvalds\r\n...\r\n```\r\n\r\n##Important\r\nParson currently supports hexadecimal and octal numbers, but they're not a part of JSON standard, so you shouldn't use them.\r\n\r\n##License\r\n[The MIT License (MIT)](http://opensource.org/licenses/mit-license.php)","name":"parson","google":"UA-35563760-2","tagline":"Small json parser and reader written in C.","note":"Don't delete this file! It's used internally to help with page regeneration."}