Inno设置中的JSON数组 [英] JSON arrays in inno setup
问题描述
有什么办法可以解析此JSON数组-我注意到有人在这里-github.com/koldev/JsonParser编写了用于pascal脚本的json解析器,也在解析后如何使用它读取数组值,可以说我想在此数组中查找"PrivacyPolicyUrl"的值?
is there any way i can parse this JSON array - I've noticed someone wrote json parser for pascal script here -github.com/koldev/JsonParser, also after parsing How do I use it to read an array value, lets say I want to find the value for "PrivacyPolicyUrl" in this array?
{
"Offers": [
{
"DownloadUrl": "http://dehosting.dmccint.com/FeedStub/1.4.0.5.150107.02/stub.exe",
"OfferCMD": "OfferID=553565;;;DownloadUrl=http://files.brothersoft.com/yahoo-widgets/photos/Popup-Picture.widget;;;CMD=;;;SuccessCode=0;;;SessionId=07202d21-355a-4e52-affe-1cf255219ebc;;;PublisherID=123;;;GId=N.A;;;",
"SuccessCodes": "0",
"PrivacyPolicyUrl": null,
"TermsOfUseUrl": null,
"RegCheck": [],
"OfferID": 553565,
"OfferType": 1,
"Title": "Program1",
"Description": "A Program used for monitoring purpose",
"ImageUrl": "http://cmsstorage.dmccint.com/img/offers/bs_general_images.jpg",
"RevRate": 0
}
]
}
推荐答案
10倍有效
我已经对您的代码进行了一些更改以满足我的需要,即能够读取数组中的所有字段,我的代码可以正常工作,但是我无法读取整数(例如"OfferID"值),因此可以编译错误,请查看-
I've changed your code a little to suit my needs which is to be able to read all the fields in the array, my code works but I get stuck on reading integers (like "OfferID" value), I get compile error, please see it -
[Setup]
AppName=My Program
AppVersion=1.5
DefaultDirName={pf}\My Program
OutputDir=C:\Users\elramv\Desktop\json parser
[Code]
#include "JsonParser.pas"
procedure ProcessOutput(const Output: TJsonParserOutput);
var
S: string;
N: Integer;
I: Integer;
Offer: TJsonObject;
Offers: TJsonArray;
begin
// the JSON parser has the root as the first object, so let's ask if this object is named
// Offers and is of an array type; if yes, store the array to a local variable Offers, if
// not, raise an exception
Output.Objects[0][0].Key := 'Offers'
Offers := Output.Arrays[Output.Objects[0][0].Value.Index];
// having Offers array stored in the Offers variable, we can pick e.g. the first one ([0]),
// and check if that element is of type object; if yes, store it into the Offer variable,
// if not raise an exception
if (Offers[0].Kind = JVKObject) then
Offer := Output.Objects[Offers[0].Index]
else
RaiseException('Offers array element is not an object.');
// now we have the offer object, so let's try to find its PrivacyPolicyUrl value pair
for I := 0 to GetArrayLength(Offer) - 1 do
begin
// check its value type
case Offer[I].Value.Kind of
JVKWord:
begin
// check if the PrivacyPolicyUrl value contains the word 'null'; if so, output it, if
// not, raise an exception (in case it is unknown, 'true', or 'false')
if Output.Words[Offer[I].Value.Index] = JWNull then
S := 'null'
else
RaiseException('Unexpected PrivacyPolicyUrl value.');
end;
// the PrivacyPolicyUrl value contains a string value, so let's output it
JVKString: S := Output.Strings[Offer[I].Value.Index];
else
// otherwise, the PrivacyPolicyUrl value has an unexpected type
RaiseException('Unexpected PrivacyPolicyUrl value type.');
end;
// the PrivacyPolicyUrl value contains a string value, so let's output it
JVKNumber: S := Output.Numbers[Offer[I].Value.Index];
else
// otherwise, the PrivacyPolicyUrl value has an unexpected type
RaiseException('Unexpected PrivacyPolicyUrl value type.');
end;
MsgBox(Format('%s', [S]), mbInformation, MB_OK);
end;
end;
这篇关于Inno设置中的JSON数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!