以下函数将查找所有user.id整数:
- void simdjson_traverse(std::vector<int64_t> &answer, ParsedJson::iterator &i) {
- switch (i.get_type()) {
- case '{':
- if (i.down()) {
- do {
- bool founduser = equals(i.get_string(), "user");
- i.next(); // move to value
- if (i.is_object()) {
- if (founduser && i.move_to_key("id")) {
- if (i.is_integer()) {
- answer.push_back(i.get_integer());
- }
- i.up();
- }
- simdjson_traverse(answer, i);
- } else if (i.is_array()) {
- simdjson_traverse(answer, i);
- }
- } while (i.next());
- i.up();
- }
- break;
- case '[':
- if (i.down()) {
- do {
- if (i.is_object_or_array()) {
- simdjson_traverse(answer, i);
- }
- } while (i.next());
- i.up();
- }
- break;
- case 'l':
- case 'd':
- case 'n':
- case 't':
- case 'f':
- default:
- break;
- }
- }
深入比较
如果您想了解各种解析器如何验证给定的JSON文件:
- make allparserscheckfile
- ./allparserscheckfile myfile.json
对于性能比较:
- make parsingcompetition
- ./parsingcompetition myfile.json
进行更广泛的比较:
- make allparsingcompetition
- ./allparsingcompetition myfile.json
【编辑推荐】 - SAP 开源 SCA 工具,扫描软件包依赖漏洞
- Gartner报告:正处于数据科学与机器学习工具 “大爆炸”的时代
- 可视化实时Web日志分析工具,堪称神器!
- 超 100000 个 GitHub 代码库泄露了 API 或加密密钥
- 如何阅读一份源代码?
【责任编辑:张燕妮 TEL:(010)68476606】
点赞 0 (编辑:晋中站长网)
【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!
|