我使用Inno JSON Config(类似于Pascal Script fails to retrieve wide string from a custom DLL)来读取一个名为items.json
的简单JSON文件:
{
"Item_0":{
"Key_1": "String 1",
"Key_2": "1",
"Key_3": "True"
},
"Item_1":{
"Key_1": "String 2",
"Key_2": "2",
"Key_3": "False"
}
}
以下是我的代码:
[Files]
Source: "JSONConfig.dll"; DestDir: "{tmp}\src"; Flags: dontcopy;
Source: "json_lists\*"; DestDir: "{tmp}\json_lists"; Flags: dontcopy;
[Code]
var
ItemList: array of WideString;
function JSONQueryString(FileName, Section, Key, Default: WideString;
var Value: WideString; var ValueLength: Integer): Boolean;
external 'JSONQueryString@files:jsonconfig.dll stdcall';
procedure AppendItem(var ItemArray: array of WideString; Item: WideString);
begin
SetLength(ItemArray, GetArrayLength(ItemArray) + 1);
ItemArray[GetArrayLength(ItemArray) - 1] := Item;
end;
function ParseJson(Filename: WideString; Item: String; Key: String; var ItemArray: array of WideString): Boolean;
var
StrValue: WideString;
StrLength: Integer;
ItemNumber: Integer;
Path: WideString;
begin
SetLength(StrValue, 32);
StrLength := Length(StrValue);
result := False;
Path := ExpandConstant('{tmp}'+ '\json_lists\' + Filename);
ItemNumber := 0;
while JSONQueryString(Path, ExpandConstant(Item + '_' + IntToStr(ItemNumber)), Key, 'Default', StrValue, StrLength) do
begin
ItemNumber := ItemNumber + 1;
AppendItem(ItemArray, StrValue);
result := True;
end;
end;
function NextButtonClick(CurPageID: Integer): Boolean;
var
I: Integer;
PathForNextFile: WideString;
begin
if CurPageID = wpWelcome then
begin
if GetArrayLength(ItemList) = 0 then begin
ExtractTemporaryFiles('{tmp}\json_lists\*');
if ParseJson('items.json','Item', 'Key_1', ItemList) then begin
for I := 0 to GetArrayLength(ItemList) - 1 do begin
PathForNextFile := ItemList[I] + '.json';
Log(PathForNextFile); //**
end;
end else begin
Log('Error while parsing')
end;
end;
end;
result := True;
end;
我在代码(第Log(PathForNextFile);
行)中有两个值为//**
的问题:
- 日志(log)只提示‘字符串’,不带以下数字(通常为0或1);
- 日志(log)不会提示后缀‘.json’.这很有问题,因为我需要后缀为‘.json’的变量
PathForNextFile
来解析另一个文件.
我不知道为什么会发生这种情况,欢迎任何帮助!
理想情况下,我只想处理String
,而不是WideString
,那么我是否应该编写一个PowerShell脚本,在Inno Setup中调用该脚本时,如果可能的话,将返回正确的信息String
?
我试着使用Koldev的JsonParser Library,但我不知道它是如何工作的,即使是How to parse a JSON string in Inno Setup?,所以仍然欢迎任何帮助!