Ich habe derzeit ein problem beim parsen eines json files, ich kriege es nicht richtig gepared er paarsed den hauptpunkt und den ersten beiden unterpunkte und fährt sich dann fest.(also die unterpunkte folgewort und anzahl)
hiermit versuche ich das json auszulesen
Code: Alles auswählen
begin
writeln('fange an zu lesen');
s := Copy(Content, 14, length(Content));
Text := '';
Text := LoadFile('./configs/' + s + '.json');
J := GetJson(Text);
//Lade Wortdatenbank
i:= 0;
i2:=0;
quit:=false;
repeat
try
writeln('lese haupt ein');
setlength(database, i+1);
database[i].wort1 := J.FindPath('Wortdatenbank['+ inttostr(i) +'].wort1').AsString;
database[i].wort1 := J.FindPath('Wortdatenbank['+ inttostr(i) +'].wort2').AsString;
writeln('ende haupteintrag');
repeat
try
writeln('lese unter ein');
setlength(database[i].folgewort, i2+1);
setlength(database[i].anzahl, i2+1);
writeln('trage ein');
database[i].folgewort[i2] := J.FindPath('Wortdatenbank['+inttostr(i) +'].folgewort['+inttostr(i2)+']').AsString;
writeln('anzahl');
database[i].anzahl[i2] := J.FindPath('Wortdatenbank['+ inttostr(i) +'].anzahl['+ inttostr(i2)+']').Asinteger;
inc(i2);
if J.FindPath('Wortdatenbank['+inttostr(i) +'].folgewort['+inttostr(i2)+']').AsString = '' then break;
except
writeln('except ausgelöst unterpunkt');
quit2:= true;
end
until quit2=true;
writeln('zurück in haupt');
i2:=0;
inc(i);
quit2 := false;
except
writeln('except ausgelöst hauptpunkt');
quit:=true;
end;
until quit=true;
text :='';
end
Code: Alles auswählen
{
"Wortdatenbank": [{
"wort1":"das",
"wort2":"ist",
"folgewort": ["ein","auf","toll","der"],
"anzahl": ["3","1","1","1"]},
{
"wort1":"ist",
"wort2":"ein",
"folgewort": ["das"],
"anzahl": ["3"]},
{
"wort1":"ein",
"wort2":"das",
"folgewort": ["ist"],
"anzahl": ["3"]},
{
"wort1":"ist",
"wort2":"auf",
"folgewort": ["der"],
"anzahl": ["1"]},
{
"wort1":"auf",
"wort2":"der",
"folgewort": ["ist"],
"anzahl": ["1"]},
{
"wort1":"der",
"wort2":"ist",
"folgewort": ["doof"],
"anzahl": ["1"]},
{
"wort1":"ist",
"wort2":"doof",
"folgewort": ["das"],
"anzahl": ["1"]},
{
"wort1":"doof",
"wort2":"das",
"folgewort": ["ist"],
"anzahl": ["1"]},
{
"wort1":"ist",
"wort2":"toll",
"folgewort": ["das"],
"anzahl": ["1"]},
{
"wort1":"toll",
"wort2":"das",
"folgewort": ["ist"],
"anzahl": ["1"]}
]}
Code: Alles auswählen
Statistiken = packed record
Wort1: string;
Wort2: string;
Folgewort: array of string;
Anzahl: array of integer;
// Vorkommen: array of single;
end;
var
database: array of Statistiken;