使用NSIS,如何从Json格式的文本文件或Json文件中获得键值?



我是jin。谢谢你看我的文章:)

我正在使用NSIS,我想通过使用c++ dll获得Json类型字符串并将其保存为文本文件或Json文件来获得内部的键值。但即使使用nsJson,我也无法获得值。我们将发送给您一个简单的例子和代码。谢谢你。

文件示例:"ex.json"或";ex.txt"

[{"areaCode":"INF0411","areaName":"NewY","gradeCode":"INF0102"},
{"areaCode":"INF0412","areaName":"NewA","gradeCode":"INF0103"},
{"areaCode":"INF0413","areaName":"NewB","gradeCode":"INF0104"},
{"areaCode":"INF0414","areaName":"NewC","gradeCode":"INF0105"}]

在这种情况下,我想获得的键值每一个"gradeCode".

感谢您的阅读。

使用/index访问数组节点:

!macro prepare_example
InitPluginsDir
FileOpen $0 "$PluginsDirdata.json" w
FileWrite $0 '[{"areaCode":"INF0411","areaName":"NewY","gradeCode":"INF0102"},$n'
FileWrite $0 '{"areaCode":"INF0412","areaName":"NewA","gradeCode":"INF0103"},$n'
FileWrite $0 '{"areaCode":"INF0413","areaName":"NewB","gradeCode":"INF0104"},$n'
FileWrite $0 '{"areaCode":"INF0414","areaName":"NewC","gradeCode":"INF0105"}]$n'
FileClose $0
!macroend
!include LogicLib.nsh
Section
!insertmacro prepare_example
ClearErrors
nsJSON::Set /file "$PluginsDirdata.json"
nsJSON::Get /count /end
Pop $1
${For} $2 0 $1
nsJSON::Get /index $2 "gradeCode" /end
${IfNot} ${Errors}
Pop $0
DetailPrint "Grade=$0"
${EndIf}
${Next}
SectionEnd

最新更新