ImageEn, unit iexUtils

TIEDictionary.Parse

TIEDictionary.Parse

Declaration

function Parse(text: WideString): Boolean;

Description

Parses the JSON-like string and populates the dictionary.
This method does not remove existing items.
Parameter Description
text JSON or XML style text

Examples

dict := TIEDictionary.Create();
dict.Parse('{"string" : "string content", "myinteger": 1234, "mydouble": 123.456, "a_bool_true" : true, "a_bool_false" : false, "subdict" : {"name": "john", "surname" : "mad"}, "array": [1,2,3,4,"hello", {}, {"alfa":"beta"}, [9,10]] }');
Memo1.Text := dict.Dump(ieplXML);
dict.Free();


// Dump the structure of the dictionary
var
  ss: TStringList;
  dict: TIEDictionary;
begin
  ss := TStringList.Create();
  dict := TIEDictionary.Create();
  ss.LoadFromFile('D:\XML_TEST.xml');
  dict.parse( ss.Text );

  // Dump structure
  Memo1.Text := dict.Dump(ieplStructure);

  dict.Free();
  ss.Free();
end;


// Parse all DictionaryEntries from XML file
// Download file from: www.imageen.com/files/UnitTestFiles/XML_TEST.xml
{
SAMPLE:

<?xml version="1.0" encoding="UTF-8"?>
<Proofreader>
 <Rules Language="EN">
   <DictionaryEntries>
     <Entry>absolute</Entry>
     <Entry>add</Entry>
     <Entry>ancestor</Entry>
     <Entry>anchor</Entry>
     <Entry>begin</Entry>
     ...


OUTPUT:

absolute
add
ancestor
anchor
begin
...
}
var
  ss: TStringList;
  xmlDict: TIEDictionary;  // Dict to parse source XML
  navDict: TIEDictionary;  // Dict to navigate XML structure
  list: TObjectList;
  i: Integer;
begin
  ss := TStringList.Create();
  xmlDict := TIEDictionary.Create();
  ss.LoadFromFile('D:\XML_TEST.xml');
  xmlDict.parse( ss.Text );

  // Output all entries of Proofreader->Rules->DictionaryEntries into "Memo1"
  navDict := xmlDict.GetDictionary('Proofreader', False);
  navDict := navDict.GetDictionary('#content', False);
  navDict := TIEDictionary(navDict.GetList('Rules', False)[0]);
  navDict := navDict.GetDictionary('#content', False);
  navDict := navDict.GetDictionary('DictionaryEntries', False);
  navDict := navDict.GetDictionary('#content', False);
  list := navDict.GetList('Entry', False);
  for i := 0 to list.Count - 1 do
  begin
    navDict := TIEDictionary(list[i]).GetDictionary('#content', False);
    Memo1.Lines.Add( navDict.GetString('#text', False) );
  end;

  xmlDict.Free();
  ss.Free();
end;

See Also

Dump