ZBLOG

上述代码编译错误:[build] /root/Desktop/615/svr/ajsqlite3.cpp:1945:46: error: ‘const key_type’ {aka ‘const class std::__cxx11::basic_string’} has no member named ‘asString’ [build] 1945 | emitter

非常抱歉,我之前的回答中没有注意到您使用的是 nlohmann::json 库而不是 jsoncpp 库。nlohmann::json 不需要像 jsoncpp 那样进行转换操作。

以下是更新后的函数示例,适用于 nlohmann::json:

  1. void jsonToYaml(const nlohmann::json& jsonData, YAML::Emitter& emitter)
  2. {
  3. if (jsonData.is_object())
  4. {
  5. emitter << YAML::BeginMap;
  6. for (auto it = jsonData.begin(); it != jsonData.end(); ++it)
  7. {
  8. emitter << YAML::Key << it.key();
  9. if(it.value().is_object() || it.value().is_array())
  10. jsonToYaml(it.value(), emitter);
  11. else
  12. emitter << YAML::Value << it.value();
  13. }
  14. emitter << YAML::EndMap;
  15. }
  16. else if (jsonData.is_array())
  17. {
  18. emitter << YAML::BeginSeq;
  19. for (const auto& item : jsonData)
  20. {
  21. jsonToYaml(item, emitter);
  22. }
  23. emitter << YAML::EndSeq;
  24. }
  25. else
  26. {
  27. // Scalar value
  28. emitter << jsonData.get<nlohmann::json::string_t>();
  29. }
  30. }

通过这些修改,代码应该能够正确编译并将 JSON 转换为 YAML 格式。希望这次能够帮到你!如果还有其他问题,请随时提问。


内容由零声教学AI助手提供,问题来源于学员提问

本站部分文章来源于网络,版权归原作者所有,如有侵权请联系站长删除。
转载请注明出处:https://golang.0voice.com/?id=17251

分享:
扫描分享到社交APP
上一篇
下一篇
发表列表
游客 游客
此处应有掌声~
评论列表

还没有评论,快来说点什么吧~

联系我们

在线咨询: 点击这里给我发消息

微信号:3007537140

上班时间: 10:30-22:30

关注我们
x

注册

已经有帐号?