我在QT中遇到了JSON数据的错误,my code on Github如果json数据少一点,代码可以编译运行,但是json数据大一点,代码就不能编译运行了。你可以克隆我的github代码来测试,我确信它可以用短json编译并运行,当你编译完成后,点击DisplayDirAndFileDifferent
按钮,你会看到下面的图片:
x1c 0d1x的数据
当json很短的时候,比如下面,代码可以编译运行:
const std::string json = R"([
{"name": "C:/my-win10-document/code/CheckDirectoryAndFileChange/build-CheckDirectoryAndFileChange-Desktop_Qt_6_5_1_MSVC2019_64bit-Debug/.qmake.stash";"LastModifiedTime": ""},
{"name": "C:/my-win10-document/code/CheckDirectoryAndFileChange/build-CheckDirectoryAndFileChange-Desktop_Qt_6_5_1_MSVC2019_64bit-Debug/.qtc_clangd";"LastModifiedTime": ""},
{"name": "C:/my-win10-document/code/CheckDirectoryAndFileChange/build-CheckDirectoryAndFileChange-Desktop_Qt_6_5_1_MSVC2019_64bit-Debug/.qtc_clangd/.cache";"LastModifiedTime": ""},
{"name": "C:/my-win10-document/code/CheckDirectoryAndFileChange/build-CheckDirectoryAndFileChange-Desktop_Qt_6_5_1_MSVC2019_64bit-Debug/.qtc_clangd/.cache/clangd";"LastModifiedTime": ""},
{"name": "C:/my-win10-document/code/CheckDirectoryAndFileChange/build-CheckDirectoryAndFileChange-Desktop_Qt_6_5_1_MSVC2019_64bit-Debug/.qtc_clangd/.cache/clangd/index";"LastModifiedTime": ""},
{"name": "C:/my-win10-document/code/CheckDirectoryAndFileChange/build-CheckDirectoryAndFileChange-Desktop_Qt_6_5_1_MSVC2019_64bit-Debug/.qtc_clangd/.cache/clangd/index/adxintrin.h.F8695614109264BF.idx";"LastModifiedTime": ""},
{"name": "C:/my-win10-document/code/CheckDirectoryAndFileChange/build-CheckDirectoryAndFileChange-Desktop_Qt_6_5_1_MSVC2019_64bit-Debug/.qtc_clangd/.cache/clangd/index/algorithm.85F84F593F617683.idx";"LastModifiedTime": ""},
{"name": "C:/my-win10-document/code/CheckDirectoryAndFileChange/build-CheckDirectoryAndFileChange-Desktop_Qt_6_5_1_MSVC2019_64bit-Debug/.qtc_clangd/.cache/clangd/index/array.4A440D58C35C1B65.idx";"LastModifiedTime": ""},
{"name": "C:/my-win10-document/code/CheckDirectoryAndFileChange/build-CheckDirectoryAndFileChange-Desktop_Qt_6_5_1_MSVC2019_64bit-Debug/.qtc_clangd/.cache/clangd/index/assert.h.1440D2C4BC469D57.idx";"LastModifiedTime": ""},
{"name": "C:/my-win10-document/code/CheckDirectoryAndFileChange/build-CheckDirectoryAndFileChange-Desktop_Qt_6_5_1_MSVC2019_64bit-Debug/.qtc_clangd/.cache/clangd/index/atomic.46B98FDAFBC57939.idx";"LastModifiedTime": ""},
{"name": "C:/my-win10-document/code/CheckDirectoryAndFileChange/build-CheckDirectoryAndFileChange-Desktop_Qt_6_5_1_MSVC2019_64bit-Debug/.qtc_clangd/.cache/clangd/index/bmiintrin.h.575071838DB7E543.idx";"LastModifiedTime": ""},
{"name": "C:/my-win10-document/code/CheckDirectoryAndFileChange/build-CheckDirectoryAndFileChange-Desktop_Qt_6_5_1_MSVC2019_64bit-Debug/.qtc_clangd/.cache/clangd/index/cctype.6CAC01960A46CBE8.idx";"LastModifiedTime": ""},
{"name": "C:/my-win10-document/code/CheckDirectoryAndFileChange/build-CheckDirectoryAndFileChange-Desktop_Qt_6_5_1_MSVC2019_64bit-Debug/.qtc_clangd/.cache/clangd/index/cerrno.D0366719F7F5D6B2.idx";"LastModifiedTime": ""},
{"name": "C:/my-win10-document/code/CheckDirectoryAndFileChange/build-CheckDirectoryAndFileChange-Desktop_Qt_6_5_1_MSVC2019_64bit-Debug/.qtc_clangd/.cache/clangd/index/cfloat.D3E6A7BCFC6D7B8F.idx";"LastModifiedTime": ""},
{"name": "C:/my-win10-document/code/CheckDirectoryAndFileChange/build-CheckDirectoryAndFileChange-Desktop_Qt_6_5_1_MSVC2019_64bit-Debug/.qtc_clangd/.cache/clangd/index/chrono.0EF46438A07D6958.idx";"LastModifiedTime": ""},
{"name": "C:/my-win10-document/code/CheckDirectoryAndFileChange/build-CheckDirectoryAndFileChange-Desktop_Qt_6_5_1_MSVC2019_64bit-Debug/.qtc_clangd/.cache/clangd/index/climits.D8FE350A98C8E969.idx";"LastModifiedTime": ""},
{"name": "C:/my-win10-document/code/CheckDirectoryAndFileChange/build-CheckDirectoryAndFileChange-Desktop_Qt_6_5_1_MSVC2019_64bit-Debug/.qtc_clangd/.cache/clangd/index/clocale.6DAA72D95FD7152A.idx";"LastModifiedTime": ""}
])";
字符串
但Json数据比较大,如下代码无法编译运行:
const std::string json = R"([
{"name": "C:/my-win10-document/code/CheckDirectoryAndFileChange/build-CheckDirectoryAndFileChange-Desktop_Qt_6_5_1_MSVC2019_64bit-Debug/.qmake.stash";"LastModifiedTime": ""},
{"name": "C:/my-win10-document/code/CheckDirectoryAndFileChange/build-CheckDirectoryAndFileChange-Desktop_Qt_6_5_1_MSVC2019_64bit-Debug/.qtc_clangd/.cache/clangd/index/cmath.892CD3F82046EB21.idx";"LastModifiedTime": ""},
{"name": "C:/my-win10-document/code/CheckDirectoryAndFileChange/build-CheckDirectoryAndFileChange-Desktop_Qt_6_5_1_MSVC2019_64bit-Debug/.qtc_clangd/.cache/clangd/index/concurrencysal.h.5DA0C09AED7DA192.idx";"LastModifiedTime": ""},
{"name": "C:/my-win10-document/code/CheckDirectoryAndFileChange/build-CheckDirectoryAndFileChange-Desktop_Qt_6_5_1_MSVC2019_64bit-Debug/.qtc_clangd/.cache/clangd/index/corecrt.h.67FFEE19928F854D.idx";"LastModifiedTime": ""},
{"name": "C:/my-win10-document/code/CheckDirectoryAndFileChange/build-CheckDirectoryAndFileChange-Desktop_Qt_6_5_1_MSVC2019_64bit-Debug/.qtc_clangd/.cache/clangd/index/corecrt_malloc.h.C0138CCDDEC903D5.idx";"LastModifiedTime": ""},
{"name": "C:/my-win10-document/code/CheckDirectoryAndFileChange/build-CheckDirectoryAndFileChange-Desktop_Qt_6_5_1_MSVC2019_64bit-Debug/.qtc_clangd/.cache/clangd/index/corecrt_math.h.0390C374A34FAE6B.idx";"LastModifiedTime": ""},
{"name": "C:/my-win10-document/code/CheckDirectoryAndFileChange/build-CheckDirectoryAndFileChange-Desktop_Qt_6_5_1_MSVC2019_64bit-Debug/.qtc_clangd/.cache/clangd/index/corecrt_memcpy_s.h.57108F1F96D1D502.idx";"LastModifiedTime": ""},
{"name": "C:/my-win10-document/code/CheckDirectoryAndFileChange/build-CheckDirectoryAndFileChange-Desktop_Qt_6_5_1_MSVC2019_64bit-Debug/.qtc_clangd/.cache/clangd/index/corecrt_memory.h.65CCD44C1265E45E.idx";"LastModifiedTime": ""},
{"name": "C:/my-win10-document/code/CheckDirectoryAndFileChange/build-CheckDirectoryAndFileChange-Desktop_Qt_6_5_1_MSVC2019_64bit-Debug/.qtc_clangd/.cache/clangd/index/corecrt_search.h.B43E2344530D0FBD.idx";"LastModifiedTime": ""},
{"name": "C:/my-win10-document/code/CheckDirectoryAndFileChange/build-CheckDirectoryAndFileChange-Desktop_Qt_6_5_1_MSVC2019_64bit-Debug/.qtc_clangd/.cache/clangd/index/corecrt_share.h.DDB39811FDF689B6.idx";"LastModifiedTime": ""},
{"name": "C:/my-win10-document/code/CheckDirectoryAndFileChange/build-CheckDirectoryAndFileChange-Desktop_Qt_6_5_1_MSVC2019_64bit-Debug/.qtc_clangd/.cache/clangd/index/corecrt_stdio_config.h.58436A96317F9ED9.idx";"LastModifiedTime": ""},
{"name": "C:/my-win10-document/code/CheckDirectoryAndFileChange/build-CheckDirectoryAndFileChange-Desktop_Qt_6_5_1_MSVC2019_64bit-Debug/.qtc_clangd/.cache/clangd/index/cstddef.18387D969F572B40.idx";"LastModifiedTime": ""},
{"name": "C:/my-win10-document/code/CheckDirectoryAndFileChange/build-CheckDirectoryAndFileChange-Desktop_Qt_6_5_1_MSVC2019_64bit-Debug/.qtc_clangd/.cache/clangd/index/cstdint.210D2F1E1255355E.idx";"LastModifiedTime": ""},
{"name": "C:/my-win10-document/code/CheckDirectoryAndFileChange/build-CheckDirectoryAndFileChange-Desktop_Qt_6_5_1_MSVC2019_64bit-Debug/.qtc_clangd/.cache/clangd/index/cstdio.9E31F70803BFA76C.idx";"LastModifiedTime": ""},
{"name": "C:/my-win10-document/code/CheckDirectoryAndFileChange/build-CheckDirectoryAndFileChange-Desktop_Qt_6_5_1_MSVC2019_64bit-Debug/.qtc_clangd/.cache/clangd/index/cstdlib.721BB85373461AF5.idx";"LastModifiedTime": ""},
{"name": "C:/my-win10-document/code/CheckDirectoryAndFileChange/build-CheckDirectoryAndFileChange-Desktop_Qt_6_5_1_MSVC2019_64bit-Debug/.qtc_clangd/.cache/clangd/index/cstring.8985911536AFC237.idx";"LastModifiedTime": ""},
{"name": "C:/my-win10-document/code/CheckDirectoryAndFileChange/build-CheckDirectoryAndFileChange-Desktop_Qt_6_5_1_MSVC2019_64bit-Debug/.qtc_clangd/.cache/clangd/index/ctime.1EFA885321907197.idx";"LastModifiedTime": ""},
{"name": "C:/my-win10-document/code/CheckDirectoryAndFileChange/build-CheckDirectoryAndFileChange-Desktop_Qt_6_5_1_MSVC2019_64bit-Debug/.qtc_clangd/.cache/clangd/index/ctype.h.BC399C448EA6DADA.idx";"LastModifiedTime": ""},
{"name": "C:/my-win10-document/code/CheckDirectoryAndFileChange/build-CheckDirectoryAndFileChange-Desktop_Qt_6_5_1_MSVC2019_64bit-Debug/.qtc_clangd/.cache/clangd/index/cwchar.1B862937C4978721.idx";"LastModifiedTime": ""},
{"name": "C:/my-win10-document/code/CheckDirectoryAndFileChange/build-CheckDirectoryAndFileChange-Desktop_Qt_6_5_1_MSVC2019_64bit-Debug/.qtc_clangd/.cache/clangd/index/eh.h.F7CF178131C9CC77.idx";"LastModifiedTime": ""},
{"name": "C:/my-win10-document/code/CheckDirectoryAndFileChange/build-CheckDirectoryAndFileChange-Desktop_Qt_6_5_1_MSVC2019_64bit-Debug/.qtc_clangd/.cache/clangd/index/emmintrin.h.6E9074898208EE3A.idx";"LastModifiedTime": ""},
{"name": "C:/my-win10-document/code/CheckDirectoryAndFileChange/build-CheckDirectoryAndFileChange-Desktop_Qt_6_5_1_MSVC2019_64bit-Debug/.qtc_clangd/.cache/clangd/index/errno.h.FE9F83F635964CFD.idx";"LastModifiedTime": ""},
{"name": "C:/my-win10-document/code/CheckDirectoryAndFileChange/build-CheckDirectoryAndFileChange-Desktop_Qt_6_5_1_MSVC2019_64bit-Debug/.qtc_clangd/.cache/clangd/index/exception.68221D83EEE0C979.idx";"LastModifiedTime": ""},
{"name": "C:/my-win10-document/code/CheckDirectoryAndFileChange/build-CheckDirectoryAndFileChange-Desktop_Qt_6_5_1_MSVC2019_64bit-Debug/.qtc_clangd/.cache/clangd/index/filesystem.EEB58F510895B243.idx";"LastModifiedTime": ""},
{"name": "C:/my-win10-document/code/CheckDirectoryAndFileChange/build-CheckDirectoryAndFileChange-Desktop_Qt_6_5_1_MSVC2019_64bit-Debug/.qtc_clangd/.cache/clangd/index/float.h.007015653F756B29.idx";"LastModifiedTime": ""},
{"name": "C:/my-win10-document/code/CheckDirectoryAndFileChange/build-CheckDirectoryAndFileChange-Desktop_Qt_6_5_1_MSVC2019_64bit-Debug/.qtc_clangd/.cache/clangd/index/float.h.D55989CBB4E7EEA3.idx";"LastModifiedTime": ""},
{"name": "C:/my-win10-document/code/CheckDirectoryAndFileChange/build-CheckDirectoryAndFileChange-Desktop_Qt_6_5_1_MSVC2019_64bit-Debug/.qtc_clangd/.cache/clangd/index/functional.F7983FBAA4462BCB.idx";"LastModifiedTime": ""},
{"name": "C:/my-win10-document/code/CheckDirectoryAndFileChange/build-CheckDirectoryAndFileChange-Desktop_Qt_6_5_1_MSVC2019_64bit-Debug/.qtc_clangd/.cache/clangd/index/fxsrintrin.h.C52DDDDFB7A8B9DB.idx";"LastModifiedTime": ""},
{"name": "C:/my-win10-document/code/CheckDirectoryAndFileChange/build-CheckDirectoryAndFileChange-Desktop_Qt_6_5_1_MSVC2019_64bit-Debug/.qtc_clangd/.cache/clangd/index/ia32intrin.h.3E30D2C597639933.idx";"LastModifiedTime": ""},
{"name": "C:/my-win10-document/code/CheckDirectoryAndFileChange/build-CheckDirectoryAndFileChange-Desktop_Qt_6_5_1_MSVC2019_64bit-Debug/.qtc_clangd/.cache/clangd/index/immintrin.h.33FF6DAB2F686F5A.idx";"LastModifiedTime": ""},
{"name": "C:/my-win10-document/code/CheckDirectoryAndFileChange/build-CheckDirectoryAndFileChange-Desktop_Qt_6_5_1_MSVC2019_64bit-Debug/.qtc_clangd/.cache/clangd/index/initializer_list.EE3DCE14C35AE786.idx";"LastModifiedTime": ""},
...
...
...
...
...
...
...
...
...
...
{"name": "C:/my-win10-document/code/CheckDirectoryAndFileChange/build-CheckDirectoryAndFileChange-Desktop_Qt_6_5_1_MSVC2019_64bit-Debug/.qtc_clangd/.cache/clangd/index/intrin.h.411A625DDB615A10.idx";"LastModifiedTime": ""},
{"name": "C:/my-win10-document/code/CheckDirectoryAndFileChange/build-CheckDirectoryAndFileChange-Desktop_Qt_6_5_1_MSVC2019_64bit-Debug/.qtc_clangd/.cache/clangd/index/intrin0.h.19F5FEEAE1E7457C.idx";"LastModifiedTime": ""},
{"name": "C:/my-win10-document/code/CheckDirectoryAndFileChange/build-CheckDirectoryAndFileChange-Desktop_Qt_6_5_1_MSVC2019_64bit-Debug/.qtc_clangd/.cache/clangd/index/intrin0.inl.h.5D396B7ADE2D7A7B.idx";"LastModifiedTime": ""},
{"name": "C:/my-win10-document/code/CheckDirectoryAndFileChange/build-CheckDirectoryAndFileChange-Desktop_Qt_6_5_1_MSVC2019_64bit-Debug/.qtc_clangd/.cache/clangd/index/iomanip.1D639BBCDBA1F3D0.idx";"LastModifiedTime": ""},
{"name": "C:/my-win10-document/code/CheckDirectoryAndFileChange/build-CheckDirectoryAndFileChange-Desktop_Qt_6_5_1_MSVC2019_64bit-Debug/.qtc_clangd/.cache/clangd/index/ios.6E488EB20885070C.idx";"LastModifiedTime": ""},
{"name": "C:/my-win10-document/code/CheckDirectoryAndFileChange/build-CheckDirectoryAndFileChange-Desktop_Qt_6_5_1_MSVC2019_64bit-Debug/.qtc_clangd/.cache/clangd/index/iosfwd.AE9C5D6643157A02.idx";"LastModifiedTime": ""},
{"name": "C:/my-win10-document/code/CheckDirectoryAndFileChange/build-CheckDirectoryAndFileChange-Desktop_Qt_6_5_1_MSVC2019_64bit-Debug/.qtc_clangd/.cache/clangd/index/isa_availability.h.8CE89F7382834217.idx";"LastModifiedTime": ""},
{"name": "C:/my-win10-document/code/CheckDirectoryAndFileChange/build-CheckDirectoryAndFileChange-Desktop_Qt_6_5_1_MSVC2019_64bit-Debug/.qtc_clangd/.cache/clangd/index/qimage.h.67597433C49CD802.idx";"LastModifiedTime": ""},
{"name": "C:/my-win10-document/code/CheckDirectoryAndFileChange/build-CheckDirectoryAndFileChange-Desktop_Qt_6_5_1_MSVC2019_64bit-Debug/.qtc_clangd/.cache/clangd/index/qinputmethod.h.77B22054D6EE2814.idx";"LastModifiedTime": ""}
])";
型
这里是My test data,我认为数据不是很大,因为它只是I write application的一段测试数据。
我谷歌搜索,但没有找到一个方法来解决它。我需要比较目录和文件的修改日期,以找到什么目录和文件更改,目录和文件是不固定的,因为用户可能想检查一些目录的文件更改。参见What do for I write application。
我读了@BoP提供的链接Compiler Error C2026。见下图:
的
我想我的问题不仅仅是字符串,还有JSON
。我应该以什么格式写入文件的目录路径,以及如何以json格式使用它。
我该怎么解决这个问题呢?谢谢。JSON格式可以非常灵活,只要代码正确。。
首次更新
当我使用@drescherjm提供的链接code时,我得到了错误,见下图(但我认为错误是每行都没有逗号结束,but except for the last line
,请参阅四个更新,可以工作json格式):
的
第二次更新
当我使用@Jarod42答案,我得到错误见下图:
的
第三次更新
I provided link每行以逗号结尾,but except for the last line
,见下图:
x1c4d 1x型
四次更新
当json数据很短时,progrma可以编译并运行。JSON是:
const std::string json = R"([
{"name": "C:/my-win10-document/code/CheckDirectoryAndFileChange/build-CheckDirectoryAndFileChange-Desktop_Qt_6_5_1_MSVC2019_64bit-Debug/.qmake.stash";"LastModifiedTime": ""},
{"name": "C:/my-win10-document/code/CheckDirectoryAndFileChange/build-CheckDirectoryAndFileChange-Desktop_Qt_6_5_1_MSVC2019_64bit-Debug/.qtc_clangd";"LastModifiedTime": ""},
{"name": "C:/my-win10-document/code/CheckDirectoryAndFileChange/build-CheckDirectoryAndFileChange-Desktop_Qt_6_5_1_MSVC2019_64bit-Debug/.qtc_clangd/.cache";"LastModifiedTime": ""},
{"name": "C:/my-win10-document/code/CheckDirectoryAndFileChange/build-CheckDirectoryAndFileChange-Desktop_Qt_6_5_1_MSVC2019_64bit-Debug/.qtc_clangd/.cache/clangd";"LastModifiedTime": ""},
{"name": "C:/my-win10-document/code/CheckDirectoryAndFileChange/build-CheckDirectoryAndFileChange-Desktop_Qt_6_5_1_MSVC2019_64bit-Debug/.qtc_clangd/.cache/clangd/index";"LastModifiedTime": ""},
{"name": "C:/my-win10-document/code/CheckDirectoryAndFileChange/build-CheckDirectoryAndFileChange-Desktop_Qt_6_5_1_MSVC2019_64bit-Debug/.qtc_clangd/.cache/clangd/index/adxintrin.h.F8695614109264BF.idx";"LastModifiedTime": ""},
{"name": "C:/my-win10-document/code/CheckDirectoryAndFileChange/build-CheckDirectoryAndFileChange-Desktop_Qt_6_5_1_MSVC2019_64bit-Debug/.qtc_clangd/.cache/clangd/index/algorithm.85F84F593F617683.idx";"LastModifiedTime": ""},
{"name": "C:/my-win10-document/code/CheckDirectoryAndFileChange/build-CheckDirectoryAndFileChange-Desktop_Qt_6_5_1_MSVC2019_64bit-Debug/.qtc_clangd/.cache/clangd/index/array.4A440D58C35C1B65.idx";"LastModifiedTime": ""},
{"name": "C:/my-win10-document/code/CheckDirectoryAndFileChange/build-CheckDirectoryAndFileChange-Desktop_Qt_6_5_1_MSVC2019_64bit-Debug/.qtc_clangd/.cache/clangd/index/assert.h.1440D2C4BC469D57.idx";"LastModifiedTime": ""},
{"name": "C:/my-win10-document/code/CheckDirectoryAndFileChange/build-CheckDirectoryAndFileChange-Desktop_Qt_6_5_1_MSVC2019_64bit-Debug/.qtc_clangd/.cache/clangd/index/atomic.46B98FDAFBC57939.idx";"LastModifiedTime": ""},
{"name": "C:/my-win10-document/code/CheckDirectoryAndFileChange/build-CheckDirectoryAndFileChange-Desktop_Qt_6_5_1_MSVC2019_64bit-Debug/.qtc_clangd/.cache/clangd/index/bmiintrin.h.575071838DB7E543.idx";"LastModifiedTime": ""}
])";
型
见下图:
型
1条答案
按热度按时间68bkxrlz1#
错误是由于msvc编译器对文字C字符串的限制。他们提出了一个替代解决方案(资源文件(这在Qt中很容易))和一个变通方案(连接相邻的拆分字符串)。
对于解决方法,它将类似于:
字符串
当你使用Qt时,我建议你使用资源文件(.qrc)。
查看他们的help page