{"id":13511492,"url":"https://github.com/miloyip/json-tutorial","last_synced_at":"2025-05-13T23:05:26.819Z","repository":{"id":37492905,"uuid":"68291988","full_name":"miloyip/json-tutorial","owner":"miloyip","description":"从零开始的 JSON 库教程","archived":false,"fork":false,"pushed_at":"2024-06-14T15:11:33.000Z","size":7469,"stargazers_count":7863,"open_issues_count":104,"forks_count":4346,"subscribers_count":210,"default_branch":"master","last_synced_at":"2025-04-30T07:45:09.809Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://zhuanlan.zhihu.com/json-tutorial","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/miloyip.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-09-15T12:30:34.000Z","updated_at":"2025-04-30T00:54:29.000Z","dependencies_parsed_at":"2024-11-19T06:05:29.926Z","dependency_job_id":null,"html_url":"https://github.com/miloyip/json-tutorial","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/miloyip%2Fjson-tutorial","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/miloyip%2Fjson-tutorial/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/miloyip%2Fjson-tutorial/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/miloyip%2Fjson-tutorial/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/miloyip","download_url":"https://codeload.github.com/miloyip/json-tutorial/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254040676,"owners_count":22004592,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-01T03:00:51.852Z","updated_at":"2025-05-13T23:05:21.795Z","avatar_url":"https://github.com/miloyip.png","language":"C","funding_links":[],"categories":["C","C/C++ 程序设计","Tutorials"],"sub_categories":["网络服务_其他"],"readme":"# 从零开始的 JSON 库教程\n\n* Milo Yip\n* 2016/9/15\n\n也许有很多同学上过 C/C++ 的课后，可以完成一些简单的编程练习，又能在一些网站刷题，但对于如何开发有实际用途的程序可能感到束手无策。本教程希望能以一个简单的项目开发形式，让同学能逐步理解如何从无到有去开发软件。\n\n为什么选择 JSON？因为它足够简单，除基本编程外不需大量技术背景知识。JSON 有标准，可按照标准逐步实现。JSON 也是实际在许多应用上会使用的格式，所以才会有大量的开源库。\n\n这是一个免费、开源的教程，如果你喜欢，也可以打赏鼓励。因为工作及家庭因素，不能保证每篇文章的首发时间，请各位见谅。\n\n## 对象与目标\n\n教程对象：学习过基本 C/C++ 编程的同学。\n\n通过这个教程，同学可以了解如何从零开始写一个 JSON 库，其特性如下：\n\n* 符合标准的 JSON 解析器和生成器\n* 手写的递归下降解析器（recursive descent parser）\n* 使用标准 C 语言（C89）\n* 跨平台／编译器（如 Windows／Linux／OS X，vc／gcc／clang）\n* 仅支持 UTF-8 JSON 文本\n* 仅支持以 `double` 存储 JSON number 类型\n* 解析器和生成器的代码合共少于 500 行\n\n除了围绕 JSON 作为例子，希望能在教程中讲述一些课题：\n\n* 测试驱动开发（test driven development, TDD）\n* C 语言编程风格\n* 数据结构\n* API 设计\n* 断言\n* Unicode\n* 浮点数\n* Github、CMake、valgrind、Doxygen 等工具\n\n## 教程大纲\n\n本教程预计分为 9 个单元，第 1-8 个单元附带练习和解答。\n\n1. [启程](tutorial01/tutorial01.md)（2016/9/15 完成）：编译环境、JSON 简介、测试驱动、解析器主要函数及各数据结构。练习 JSON 布尔类型的解析。[启程解答篇](tutorial01_answer/tutorial01_answer.md)（2016/9/17 完成）。\n2. [解析数字](tutorial02/tutorial02.md)（2016/9/18 完成）：JSON number 的语法。练习 JSON number 类型的校验。[解析数字解答篇](tutorial02_answer/tutorial02_answer.md)（2016/9/20 完成）。\n3. [解析字符串](tutorial03/tutorial03.md)（2016/9/22 完成）：使用 union 存储 variant、自动扩展的堆栈、JSON string 的语法、valgrind。练习最基本的 JSON string 类型的解析、内存释放。[解析字符串解答篇](tutorial03_answer/tutorial03_answer.md)（2016/9/27 完成）。\n4. [Unicode](tutorial04/tutorial04.md)（2016/10/2 完成）：Unicode 和 UTF-8 的基本知识、JSON string 的 unicode 处理。练习完成 JSON string 类型的解析。[Unicode 解答篇](tutorial04_answer/tutorial04_answer.md)（2016/10/6 完成）。\n5. [解析数组](tutorial05/tutorial05.md)（2016/10/7 完成）：JSON array 的语法。练习完成 JSON array 类型的解析、相关内存释放。[解析数组解答篇](tutorial05_answer/tutorial05_answer.md)（2016/10/13 完成）。\n6. [解析对象](tutorial06/tutorial06.md)（2016/10/29 完成）：JSON object 的语法、重构 string 解析函数。练习完成 JSON object 的解析、相关内存释放。[解析对象解答篇](tutorial06_answer/tutorial06_answer.md)（2016/11/15 完成）。\n7. [生成器](tutorial07/tutorial07.md)（2016/12/20 完成）：JSON 生成过程、注意事项。练习完成 JSON 生成器。[生成器解答篇](tutorial07_answer/tutorial07_answer.md)（2017/1/5 完成）。\n8. [访问与其他功能](tutorial08/tutorial08.md)（2018/6/2 完成）：JSON array／object 的访问及修改。练习完成相关功能。\n9. 终点及新开始：加入 nativejson-benchmark 测试，与 RapidJSON 对比及展望。\n\n## 关于作者\n\n叶劲峰（Milo Yip）现任腾讯 T4 专家、互动娱乐事业群魔方工作室群游戏客户端技术总监。他获得香港大学认知科学学士（BCogSc）、香港中文大学系统工程及工程管理哲学硕士（MPhil）。他是《游戏引擎架构》译者、《C++ Primer 中文版（第五版）》审校。他曾参与《天涯明月刀》、《斗战神》、《爱丽丝：疯狂回归》、《美食从天降》、《王子传奇》等游戏项目，以及多个游戏引擎及中间件的研发。他是开源项目 [RapidJSON](https://github.com/miloyip/rapidjson) 的作者，开发 [nativejson-benchmark](https://github.com/miloyip/nativejson-benchmark) 比较 41 个开源原生 JSON 库的标准符合程度及性能。他在 1990 年学习 C 语言，1995 年开始使用 C++ 于各种项目。\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmiloyip%2Fjson-tutorial","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmiloyip%2Fjson-tutorial","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmiloyip%2Fjson-tutorial/lists"}