//通过 ISuperObject.GetEnumerator 可获取一个 TSuperEnumerator 对象. //TSuperEnumerator 主要有: MoveNext 方法、Current 属性; 使用举例: //-------------------------------------------------------------------------------- var jo: ISuperObject; e: TSuperEnumerator; begin jo := SO('{A:1, B:2, C:3, D:[4, 5, {X:6}, {Y:[7,8,{m:9}]}]}'); e := jo.GetEnumerator; while e.MoveNext do begin ShowMessage(e.Current.AsString); end; e.Free; end; //上面程序其实没有实用价值, 因为下面一句话就可以代替上面这些: var jo,i: ISuperObject; begin jo := SO('{A:1, B:2, C:3, D:[4, 5, {X:6}, {Y:[7,8,{m:9}]}]}'); for i in jo do ShowMessage(i.AsString); end; //-------------------------------------------------------------------------------- //同通过 TSuperEnumerator 枚举出的只有 Name:Value 中的 Value; //通过 TSuperAvlIterator 枚举出的是 TSuperAvlEntry 对象(其包含 Name 和 Value); //获取 TSuperAvlIterator 方法: //TSuperTableString.GetEnumerator 或者 ISuperObject.AsObject.GetEnumerator. //-------------------------------------------------------------------------------- var jo: ISuperObject; ite: TSuperAvlIterator; begin jo := SO('{A:1, B:2, C:3, D:[4, 5, {X:6}, {Y:7}]}'); ite := jo.AsObject.GetEnumerator; ite.First; ShowMessageFmt('%s : %s', [ite.Current.Name, ite.Current.Value.AsString]); ite.Next; ShowMessageFmt('%s : %s', [ite.Current.Name, ite.Current.Value.AsString]); ite.Last; ShowMessageFmt('%s : %s', [ite.Current.Name, ite.Current.Value.AsString]); ite.Prior; ShowMessageFmt('%s : %s', [ite.Current.Name, ite.Current.Value.AsString]); ite.Free; end; //-------------------------------------------------------------------------------- //ObjectFindFirst、ObjectFindNext、ObjectFindClose 是 SuperObject 给的另一种枚举元素的方式. //它用到了一个结构: //-------------------------------------------------------------------------------- TSuperObjectIter = record key: SOString; val: ISuperObject; Ite: TSuperAvlIterator; end; //应用举例: var jo: ISuperObject; iter: TSuperObjectIter; begin jo := SO('{A:1, B:2, C:3, D:[4, 5, {X:6}, {Y:7}]}'); if ObjectFindFirst(jo, iter) then begin repeat ShowMessageFmt('%s - %s', [iter.key, iter.val.AsString]); until not ObjectFindNext(iter); end; ObjectFindClose(iter); end; //或者: var jo: ISuperObject; iter: TSuperObjectIter; begin jo := SO('{A:1, B:2, C:3, D:[4, 5, {X:6}, {Y:7}]}'); if ObjectFindFirst(jo, iter) then begin repeat ShowMessageFmt('%s - %s', [iter.Ite.Current.Name, iter.Ite.Current.Value.AsString]); until not ObjectFindNext(iter); end; ObjectFindClose(iter); end;