【问题标题】:Calling method nlohmann::json::dump from visual studio intermediate window从 Visual Studio 中间窗口调用方法 nlohmann::json::dump
【发布时间】:2020-07-16 21:11:16
【问题描述】:

我正在尝试将 nlohmann::json 类型的对象转储为来自 Visual Studio 调试器的可读字符串值。因此,为了从 nlohmann::json 实例调用转储方法,我使用了 Visual Studio 中间窗口。

但是,尽管我完全按照我应该的方式调用它,但似乎此方法运行不佳并返回 too few arguments in function call 错误。此外,如果我尝试将其输出设置为新的 std::string 类型,调试器将无法识别它。

myJsonObj
{m_type=object (1 '\x1') m_value={object=0x000001303ea66590 { size=2 } array=0x000001303ea66590 { size=1152921422937066337 } ...} }
    m_type: object (1 '\x1')
    m_value: {object=0x000001303ea66590 { size=2 } array=0x000001303ea66590 { size=1152921422937066337 } string=0x000001303ea66590 "0A_>0\x1" ...}

myJsonObj.dump()
too few arguments in function call

std::string x = myJsonObj.dump()
identifier "x" is undefined

知道如何正确地做到这一点吗?

【问题讨论】:

    标签: c++ windows visual-studio debugging nlohmann-json


    【解决方案1】:

    在中间窗口中,我们不能使用 C++ 函数的默认参数。您可以像这样调用转储方法:

    myJsonObj.dump(4, ' ', true, nlohmann::detail::error_handler_t::strict)
    

    但是,在中间窗口中,我们看不到格式精美的打印件。您可以使用 Visual Studio Watch Window 来显示返回的字符串。请参阅此处的链接以了解如何使用 Watch 窗口: How to make Visual Studio's Immediate window give me plain string output?

    【讨论】:

      猜你喜欢
      • 2020-03-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-08-26
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多