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

Using NSIS, How can I get the Key Value from a text file in Json format or a Json file?

我是金。 感谢阅读我的文章:)

我用的是NSIS,想通过C++ dll获取里面的key值,得到一个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"}]

在这种情况下,我想得到键值 每个“等级代码”。

感谢阅读。

使用 /index 访问数组节点:

!macro prepare_example
InitPluginsDir
FileOpen [=10=] "$PluginsDir\data.json" w
FileWrite [=10=] '[{"areaCode":"INF0411","areaName":"NewY","gradeCode":"INF0102"},$\n'
FileWrite [=10=] '{"areaCode":"INF0412","areaName":"NewA","gradeCode":"INF0103"},$\n'
FileWrite [=10=] '{"areaCode":"INF0413","areaName":"NewB","gradeCode":"INF0104"},$\n'
FileWrite [=10=] '{"areaCode":"INF0414","areaName":"NewC","gradeCode":"INF0105"}]$\n'
FileClose [=10=]
!macroend

!include LogicLib.nsh
Section
!insertmacro prepare_example

ClearErrors
nsJSON::Set /file "$PluginsDir\data.json"
nsJSON::Get /count /end
Pop 
${For}  0 
    nsJSON::Get /index  "gradeCode" /end
    ${IfNot} ${Errors}
        Pop [=10=]
        DetailPrint "Grade=[=10=]"
    ${EndIf}
    ${Next}

SectionEnd