나는 설정을 아래처럼 간단한 JSON 설정 파일 작업을 수행 할 수 있습니다 Inno JSON Config
라는 새로운 프로젝트를했습니다 당신이 읽고 문자열, 정수와 부울 값을 기록 할 수있는 :
{
"Section_1":{
"Key_1": "String 1",
"Key_2": "1",
"Key_3": "True"
},
"Section_2":{
"Key_1": "String 2",
"Key_2": "2",
"Key_3": "False"
}
}
사용법은 매우 간단합니다 (핸들 지원을 추가 할 때조차도).
[Files]
Source: "JSONConfig.dll"; Flags: dontcopy
[Code]
function JSONQueryString(FileName, Section, Key, Default: WideString;
var Value: WideString; var ValueLength: Integer): Boolean;
external '[email protected]:jsonconfig.dll stdcall';
function JSONQueryBoolean(FileName, Section, Key: WideString;
Default: Boolean; var Value: Boolean): Boolean;
external '[email protected]:jsonconfig.dll stdcall';
function JSONQueryInteger(FileName, Section, Key: WideString;
Default: Int64; var Value: Int64): Boolean;
external '[email protected]:jsonconfig.dll stdcall';
function JSONWriteString(FileName, Section, Key,
Value: WideString): Boolean;
external '[email protected]:jsonconfig.dll stdcall';
function JSONWriteBoolean(FileName, Section, Key: WideString;
Value: Boolean): Boolean;
external '[email protected]:jsonconfig.dll stdcall';
function JSONWriteInteger(FileName, Section, Key: WideString;
Value: Int64): Boolean;
external '[email protected]:jsonconfig.dll stdcall';
function BoolToStr(Value: Boolean): string;
begin
Result := 'True';
if not Value then
Result := 'False';
end;
procedure InitializeWizard;
var
FileName: WideString;
IntValue: Int64;
StrValue: WideString;
StrLength: Integer;
BoolValue: Boolean;
begin
{ set the source JSON config file path }
FileName := 'c:\Example.json';
{ allocate string buffer to enough length }
SetLength(StrValue, 16);
{ set the buffer length value }
StrLength := Length(StrValue);
{ query string value }
if JSONQueryString(FileName, 'Section_1', 'Key_1', 'Default', StrValue,
StrLength)
then
MsgBox('Section_1:Key_1=' + StrValue, mbInformation, MB_OK);
{ query integer value }
if JSONQueryInteger(FileName, 'Section_1', 'Key_2', 0, IntValue) then
MsgBox('Section_1:Key_2=' + IntToStr(IntValue), mbInformation, MB_OK);
{ query boolean value }
if JSONQueryBoolean(FileName, 'Section_1', 'Key_3', True, BoolValue) then
MsgBox('Section_1:Key_3=' + BoolToStr(BoolValue), mbInformation, MB_OK);
{ write string }
if not JSONWriteString(FileName, 'Section_1', 'Key_1', 'New value!') then
MsgBox('JSONWriteString Section_1:Key_1 failed!', mbError, MB_OK);
{ write integer }
if not JSONWriteInteger(FileName, 'Section_1', 'Key_2', 123) then
MsgBox('JSONWriteInteger Section_1:Key_2 failed!', mbError, MB_OK);
{ write boolean }
if not JSONWriteBoolean(FileName, 'Section_1', 'Key_3', False) then
MsgBox('JSONWriteBoolean Section_1:Key_3 failed!', mbError, MB_OK);
end;
이노는 네이티브 JSON 지원하지 않습니다,하지만 당신은 구문 분석하고 수정할 수 있습니다 : (인해 필요한
Int64
지원 최신 버전 중 하나) 유니 코드 Inno Setup으로 사용할 수 있음을 유의 정상적인 문자열을 다시 쓰기 전에. regexp 모듈이 당신을위한 가장 쉬운 방법이라면 그렇게 될 것입니다. – Deanna알려진 고유 마커를 검색하고 바꾸려면 'StringChange' 또는'StringChangeEx' 함수를 사용하십시오. 검색 텍스트를 고유하지 않으면 정규 표현식을 사용할 필요가 없습니다. – Miral