服务器要支持Http协议,打算采用Http+JSON的方式来交换数据。一开始考虑使用superobject,因为以前使用比较多,比较熟悉。
代码如下:
1 class function FDQueryToSJSON(aQuery : TFDQuery) : string; 2 3 class function TFDQueryJSONReflect.FDQueryToSJSON(aQuery: TFDQuery): string; 4 var 5 sj,aj,sj2,aj2:ISuperObject; 6 i:Integer; 7 Fieldtyp,JsonTyp:string; 8 List:TStringList; 9 aField : TField; 10 Fields : string; 11 begin 12 // 得到一个JSON对象 13 sj := SO(); 14 //创建列 15 aj := SA([]); 16 List := TStringList.Create; 17 try 18 List.Sorted := True; 19 20 Fields := '{'; 21 for i := 0 to aQuery.FieldCount - 1 do 22 begin 23 sj2 := SO(); 24 GetFieldTypeInfo(aQuery.Fields[i],Fieldtyp,JsonTyp); 25 26 sj2.S[cstFieldName] := aQuery.Fields[i].FieldName; 27 sj2.S[cstFieldType] := Fieldtyp; 28 sj2.S[cstJsonType] := JsonTyp; 29 sj2.I[cstFieldSize] := aQuery.Fields[i].Size; 30 sj2.B[cstRequired] := aQuery.Fields[i].Required; 31 sj2.I[cstFieldIndex] := aQuery.Fields[i].Index; 32 aj.AsArray.Add(sj2); 33 List.Add(aQuery.Fields[i].FieldName+'='+JsonTyp); 34 Fields := Fields+aQuery.Fields[i].FieldName+':'+'0'+','; 35 end; 36 Fields := Fields.TrimRight([',']); 37 Fields := Fields+'}'; 38 39 sj.O['Fields'] := SO(Fields); 40 sj.O['Cols'] := aj; 41 //创建数据集的数据 42 aQuery.DisableControls; 43 aQuery.First; 44 45 aj2 := SA([]); 46 while not aQuery.Eof do 47 begin 48 sj2 := SO(); 49 for i := 0 to List.Count - 1 do 50 begin 51 aField := aQuery.Fields.FindField(List.Names[i]); 52 53 if VarIsNull(aField.Value) then 54 sj2.O[aField.FieldName] := SO(Null) 55 else 56 begin 57 CreateJsonValueByField(sj2,aField); 58 end; 59 end; 60 aj2.AsArray.Add(sj2); 61 aQuery.Next; 62 end; 63 64 sj.O['Data'] := aj2; 65 Result := sj.AsString; 66 finally 67 List.Free; 68 aQuery.EnableControls; 69 end; 70 end;
1 class function CreateJsonValueByField(Json:ISuperObject;Field:TField):Boolean; overload; 2 3 class function TFDQueryJSONReflect.CreateJsonValueByField(Json: ISuperObject; 4 Field: TField): Boolean; 5 begin 6 Result := False; 7 if (Field Is TDateTimeField) or (Field is TSQLTimeStampField) then 8 Json.O[Field.FieldName] := SO(Field.AsDateTime) 9 else if Field is TBlobField then 10 Json.S[Field.FieldName] := EncodeString(Field.AsString) 11 else 12 Json.O[Field.FieldName] := SO(Field.Value); 13 Result := True; 14 end;
这样写,没问题,可以得到结果,但是我觉得冗余的数据比较多,有些信息是不需要每行都返回的。比如字段名,每条记录都返回了。
但是当我想去掉Data的字段名时,才注意到JSON串里面的顺序和字段的顺序居然不是一致的,无论我怎么插入,只要是用SuperObject的接口去生成JSON串,
顺序都会被自动按照一种我目前没理解的方式排序。除非我自己用字符串去拼装JSON串。
该方法得到的结果如下:
{"Fields":{"base_schema_ver":0,"sysstat":0,"deltrig":0,"parent_obj":0,"schema_ver":0,"uid":0,"refdate":0,"userstat":0,"status":0,"crdate":0,"xtype":0,"indexdel":0,"version":0,"id":0,"stats_schema_ver":0,"seltrig":0,"type":0,"name":0,"info":0,"cache":0,"replinfo":0,"updtrig":0,"ftcatid":0,"category":0,"instrig":0},"Data":[{"base_schema_ver":0,"sysstat":1,"deltrig":0,"parent_obj":0,"schema_ver":0,"uid":4,"refdate":1270198761910,"userstat":1,"status":0,"crdate":1270198761910,"xtype":"S","indexdel":0,"version":0,"id":3,"stats_schema_ver":0,"seltrig":0,"type":"S","name":"sysrscols","info":0,"cache":0,"replinfo":0,"updtrig":0,"ftcatid":0,"category":2,"instrig":0},{"base_schema_ver":0,"sysstat":1,"deltrig":0,"parent_obj":0,"schema_ver":0,"uid":4,"refdate":1270198761277,"userstat":1,"status":0,"crdate":1270198761277,"xtype":"S","indexdel":0,"version":0,"id":5,"stats_schema_ver":0,"seltrig":0,"type":"S","name":"sysrowsets","info":0,"cache":0,"replinfo":0,"updtrig":0,"ftcatid":0,"category":2,"instrig":0},{"base_schema_ver":0,"sysstat":1,"deltrig":0,"parent_obj":0,"schema_ver":0,"uid":4,"refdate":1270198761273,"userstat":1,"status":0,"crdate":1270198761273,"xtype":"S","indexdel":0,"version":0,"id":7,"stats_schema_ver":0,"seltrig":0,"type":"S","name":"sysallocunits","info":0,"cache":0,"replinfo":0,"updtrig":0,"ftcatid":0,"category":2,"instrig":0},{"base_schema_ver":0,"sysstat":1,"deltrig":0,"parent_obj":0,"schema_ver":0,"uid":4,"refdate":1049764417267,"userstat":1,"status":0,"crdate":1049764417267,"xtype":"S","indexdel":0,"version":0,"id":8,"stats_schema_ver":0,"seltrig":0,"type":"S","name":"sysfiles1","info":0,"cache":0,"replinfo":0,"updtrig":0,"ftcatid":0,"category":2,"instrig":0},{"base_schema_ver":0,"sysstat":1,"deltrig":0,"parent_obj":0,"schema_ver":0,"uid":4,"refdate":1270198762227,"userstat":1,"status":0,"crdate":1270198762227,"xtype":"S","indexdel":0,"version":0,"id":17,"stats_schema_ver":0,"seltrig":0,"type":"S","name":"syspriorities","info":0,"cache":0,"replinfo":0,"updtrig":0,"ftcatid":0,"category":2,"instrig":0},{"base_schema_ver":0,"sysstat":1,"deltrig":0,"parent_obj":0,"schema_ver":0,"uid":4,"refdate":1270198761840,"userstat":1,"status":0,"crdate":1270198761840,"xtype":"S","indexdel":0,"version":0,"id":18,"stats_schema_ver":0,"seltrig":0,"type":"S","name":"sysdbfrag","info":0,"cache":0,"replinfo":0,"updtrig":0,"ftcatid":0,"category":2,"instrig":0},{"base_schema_ver":0,"sysstat":1,"deltrig":0,"parent_obj":0,"schema_ver":0,"uid":4,"refdate":1270198761853,"userstat":1,"status":0,"crdate":1270198761853,"xtype":"S","indexdel":0,"version":0,"id":19,"stats_schema_ver":0,"seltrig":0,"type":"S","name":"sysfgfrag","info":0,"cache":0,"replinfo":0,"updtrig":0,"ftcatid":0,"category":2,"instrig":0},{"base_schema_ver":0,"sysstat":1,"deltrig":0,"parent_obj":0,"schema_ver":0,"uid":4,"refdate":1270198761847,"userstat":1,"status":0,"crdate":1270198761847,"xtype":"S","indexdel":0,"version":0,"id":21,"stats_schema_ver":0,"seltrig":0,"type":"S","name":"syspru","info":0,"cache":0,"replinfo":0,"updtrig":0,"ftcatid":0,"category":2,"instrig":0},{"base_schema_ver":0,"sysstat":1,"deltrig":0,"parent_obj":0,"schema_ver":0,"uid":4,"refdate":1270198761850,"userstat":1,"status":0,"crdate":1270198761850,"xtype":"S","indexdel":0,"version":0,"id":22,"stats_schema_ver":0,"seltrig":0,"type":"S","name":"sysbrickfiles","info":0,"cache":0,"replinfo":0,"updtrig":0,"ftcatid":0,"category":2,"instrig":0},{"base_schema_ver":0,"sysstat":1,"deltrig":0,"parent_obj":0,"schema_ver":0,"uid":4,"refdate":1270198761857,"userstat":1,"status":0,"crdate":1270198761857,"xtype":"S","indexdel":0,"version":0,"id":23,"stats_schema_ver":0,"seltrig":0,"type":"S","name":"sysphfg","info":0,"cache":0,"replinfo":0,"updtrig":0,"ftcatid":0,"category":2,"instrig":0},{"base_schema_ver":0,"sysstat":1,"deltrig":0,"parent_obj":0,"schema_ver":0,"uid":4,"refdate":1270198761860,"userstat":1,"status":0,"crdate":1270198761860,"xtype":"S","indexdel":0,"version":0,"id":24,"stats_schema_ver":0,"seltrig":0,"type":"S","name":"sysprufiles","info":0,"cache":0,"replinfo":0,"updtrig":0,"ftcatid":0,"category":2,"instrig":0},{"base_schema_ver":0,"sysstat":1,"deltrig":0,"parent_obj":0,"schema_ver":0,"uid":4,"refdate":1270198761360,"userstat":1,"status":0,"crdate":1270198761360,"xtype":"S","indexdel":0,"version":0,"id":25,"stats_schema_ver":0,"seltrig":0,"type":"S","name":"sysftinds","info":0,"cache":0,"replinfo":0,"updtrig":0,"ftcatid":0,"category":2,"instrig":0},{"base_schema_ver":0,"sysstat":1,"deltrig":0,"parent_obj":0,"schema_ver":0,"uid":4,"refdate":1270198761357,"userstat":1,"status":0,"crdate":1270198761357,"xtype":"S","indexdel":0,"version":0,"id":27,"stats_schema_ver":0,"seltrig":0,"type":"S","name":"sysowners","info":0,"cache":0,"replinfo":0,"updtrig":0,"ftcatid":0,"category":2,"instrig":0},{"base_schema_ver":0,"sysstat":1,"deltrig":0,"parent_obj":0,"schema_ver":0,"uid":4,"refdate":1270198761300,"userstat":1,"status":0,"crdate":1270198761300,"xtype":"S","indexdel":0,"version":0,"id":28,"stats_schema_ver":0,"seltrig":0,"type":"S","name":"sysdbreg","info":0,"cache":0,"replinfo":0,"updtrig":0,"ftcatid":0,"category":2,"instrig":0},{"base_schema_ver":0,"sysstat":1,"deltrig":0,"parent_obj":0,"schema_ver":0,"uid":4,"refdate":1270198761267,"userstat":1,"status":0,"crdate":1270198761267,"xtype":"S","indexdel":0,"version":0,"id":29,"stats_schema_ver":0,"seltrig":0,"type":"S","name":"sysprivs","info":0,"cache":0,"replinfo":0,"updtrig":0,"ftcatid":0,"category":2,"instrig":0},{"base_schema_ver":0,"sysstat":1,"deltrig":0,"parent_obj":0,"schema_ver":0,"uid":4,"refdate":1270198761323,"userstat":1,"status":0,"crdate":1270198761323,"xtype":"S","indexdel":0,"version":0,"id":34,"stats_schema_ver":0,"seltrig":0,"type":"S","name":"sysschobjs","info":0,"cache":0,"replinfo":0,"updtrig":0,"ftcatid":0,"category":2,"instrig":0},{"base_schema_ver":0,"sysstat":1,"deltrig":0,"parent_obj":0,"schema_ver":0,"uid":4,"refdate":1270198761520,"userstat":1,"status":0,"crdate":1270198761520,"xtype":"S","indexdel":0,"version":0,"id":39,"stats_schema_ver":0,"seltrig":0,"type":"S","name":"syslogshippers","info":0,"cache":0,"replinfo":0,"updtrig":0,"ftcatid":0,"category":2,"instrig":0},{"base_schema_ver":0,"sysstat":1,"deltrig":0,"parent_obj":0,"schema_ver":0,"uid":4,"refdate":1270198761337,"userstat":1,"status":0,"crdate":1270198761337,"xtype":"S","indexdel":0,"version":0,"id":41,"stats_schema_ver":0,"seltrig":0,"type":"S","name":"syscolpars","info":0,"cache":0,"replinfo":0,"updtrig":0,"ftcatid":0,"category":2,"instrig":0},{"base_schema_ver":0,"sysstat":1,"deltrig":0,"parent_obj":0,"schema_ver":0,"uid":4,"refdate":1270198761313,"userstat":1,"status":0,"crdate":1270198761313,"xtype":"S","indexdel":0,"version":0,"id":42,"stats_schema_ver":0,"seltrig":0,"type":"S","name":"sysxlgns","info":0,"cache":0,"replinfo":0,"updtrig":0,"ftcatid":0,"category":2,"instrig":0},{"base_schema_ver":0,"sysstat":1,"deltrig":0,"parent_obj":0,"schema_ver":0,"uid":4,"refdate":1270198761307,"userstat":1,"status":0,"crdate":1270198761307,"xtype":"S","indexdel":0,"version":0,"id":43,"stats_schema_ver":0,"seltrig":0,"type":"S","name":"sysxsrvs","info":0,"cache":0,"replinfo":0,"updtrig":0,"ftcatid":0,"category":2,"instrig":0}],"Cols":[{"JsonType":"string","FieldIndex":0,"FieldType":"WideString","FieldSize":128,"FieldName":"name","Required":true},{"JsonType":"integer","FieldIndex":1,"FieldType":"Integer","FieldSize":0,"FieldName":"id","Required":true},{"JsonType":"string","FieldIndex":2,"FieldType":"String","FieldSize":2,"FieldName":"xtype","Required":true},{"JsonType":"integer","FieldIndex":3,"FieldType":"Smallint","FieldSize":0,"FieldName":"uid","Required":false},{"JsonType":"integer","FieldIndex":4,"FieldType":"Smallint","FieldSize":0,"FieldName":"info","Required":false},{"JsonType":"integer","FieldIndex":5,"FieldType":"Integer","FieldSize":0,"FieldName":"status","Required":false},{"JsonType":"integer","FieldIndex":6,"FieldType":"Integer","FieldSize":0,"FieldName":"base_schema_ver","Required":false},{"JsonType":"integer","FieldIndex":7,"FieldType":"Integer","FieldSize":0,"FieldName":"replinfo","Required":false},{"JsonType":"integer","FieldIndex":8,"FieldType":"Integer","FieldSize":0,"FieldName":"parent_obj","Required":true},{"JsonType":"variant","FieldIndex":9,"FieldType":"TimeStamp","FieldSize":0,"FieldName":"crdate","Required":true},{"JsonType":"integer","FieldIndex":10,"FieldType":"Smallint","FieldSize":0,"FieldName":"ftcatid","Required":false},{"JsonType":"integer","FieldIndex":11,"FieldType":"Integer","FieldSize":0,"FieldName":"schema_ver","Required":false},{"JsonType":"integer","FieldIndex":12,"FieldType":"Integer","FieldSize":0,"FieldName":"stats_schema_ver","Required":false},{"JsonType":"string","FieldIndex":13,"FieldType":"String","FieldSize":2,"FieldName":"type","Required":false},{"JsonType":"integer","FieldIndex":14,"FieldType":"Smallint","FieldSize":0,"FieldName":"userstat","Required":false},{"JsonType":"integer","FieldIndex":15,"FieldType":"Smallint","FieldSize":0,"FieldName":"sysstat","Required":false},{"JsonType":"integer","FieldIndex":16,"FieldType":"Smallint","FieldSize":0,"FieldName":"indexdel","Required":false},{"JsonType":"variant","FieldIndex":17,"FieldType":"TimeStamp","FieldSize":0,"FieldName":"refdate","Required":true},{"JsonType":"integer","FieldIndex":18,"FieldType":"Integer","FieldSize":0,"FieldName":"version","Required":false},{"JsonType":"integer","FieldIndex":19,"FieldType":"Integer","FieldSize":0,"FieldName":"deltrig","Required":false},{"JsonType":"integer","FieldIndex":20,"FieldType":"Integer","FieldSize":0,"FieldName":"instrig","Required":false},{"JsonType":"integer","FieldIndex":21,"FieldType":"Integer","FieldSize":0,"FieldName":"updtrig","Required":false},{"JsonType":"integer","FieldIndex":22,"FieldType":"Integer","FieldSize":0,"FieldName":"seltrig","Required":false},{"JsonType":"integer","FieldIndex":23,"FieldType":"Integer","FieldSize":0,"FieldName":"category","Required":false},{"JsonType":"integer","FieldIndex":24,"FieldType":"Smallint","FieldSize":0,"FieldName":"cache","Required":false}]}
看到没?Cols和Data的字段顺序是不一致的!Fields是我在循环里面用字符串拼装的(最开始不是这样写的,我以为我手工拼装可以得到预期的顺序,但是因为用了 SO(Fields) 得到JSON
串,所以顺序依然和Cols保持了一致,而这个顺序不是 Select 语句的得到数据集的字段顺序(调试的时候,包括得到的运行时的字符串的内容都和数据集是一致的,但一旦生成为JSON串
以后,顺序就改变了。)。
于是,我决定用QJSON去尝试一下,QJSON得到的结果顺序和我预期是一致的。
代码如下:
1 class function FDQueryToQJSON(aQuery : TFDQuery) : string; 2 3 class function TFDQueryJSONReflect.FDQueryToQJSON(aQuery: TFDQuery): string; 4 var 5 i:Integer; 6 Fieldtyp,JsonTyp:string; 7 List:TStringList; 8 aField : TField; 9 aqjsonall, aqjson,aqjson2, aqFields, aqjsonTemp : TQJSON; 10 begin 11 aqjsonall := TQJSON.Create; 12 aqjson := aqjsonall.AddArray('Cols'); 13 List := TStringList.Create; 14 try 15 List.Sorted := False; 16 17 aqFields := aqjsonall.AddArray(cstFields); 18 19 for i := 0 to aQuery.FieldCount - 1 do 20 begin 21 aqjsonTemp := TQJson.Create; 22 23 GetFieldTypeInfo(aQuery.Fields[i],Fieldtyp,JsonTyp); 24 25 aqjsonTemp.AddVariant(cstFieldName,aQuery.Fields[i].FieldName); 26 aqjsonTemp.AddVariant(cstFieldType,Fieldtyp); 27 aqjsonTemp.AddVariant(cstJsonType,JsonTyp); 28 aqjsonTemp.AddVariant(cstFieldSize, aQuery.Fields[i].Size); 29 aqjsonTemp.AddVariant(cstRequired, aQuery.Fields[i].Required); 30 aqjsonTemp.AddVariant(cstFieldIndex, aQuery.Fields[i].Index); 31 32 aqjson.Add(aqjsonTemp); 33 List.Add(aQuery.Fields[i].FieldName+'='+JsonTyp); 34 35 aqFields.Add.AsString := aQuery.Fields[i].FieldName; 36 end; 37 38 //创建数据集的数据 39 aQuery.DisableControls; 40 aQuery.First; 41 42 aqjson2 := aqjsonall.AddArray(cstData); 43 44 while not aQuery.Eof do 45 begin 46 aqjsonTemp := aqjson2.AddArray('DataItem'); 47 for i := 0 to List.Count - 1 do 48 begin 49 aField := aQuery.Fields.FindField(List.Names[i]); 50 51 if VarIsNull(aField.Value) then 52 aqjsonTemp.Add.AsString := SO(Null).AsString 53 else 54 begin 55 CreateJsonValueByField(aqjsonTemp,aField); 56 end; 57 end; 58 aQuery.Next; 59 end; 60 Result := aqjsonall.AsString; 61 finally 62 List.Free; 63 aQuery.EnableControls; 64 aqjsonall.Free; 65 end; 66 end;
1 class function CreateJsonValueByField(Json:TQJSON;Field:TField):Boolean; overload; 2 3 class function TFDQueryJSONReflect.CreateJsonValueByField(Json: TQJSON; 4 Field: TField): Boolean; 5 begin 6 Result := False; 7 if (Field Is TDateTimeField) or (Field is TSQLTimeStampField) then 8 Json.Add.AsString := FormatdateTime('yyyy-MM-dd hh:mm:ss', Field.AsDateTime) 9 else if Field is TBlobField then 10 Json.add.AsString := EncodeString(Field.AsString) 11 else 12 Json.Add.AsVariant := Field.Value; 13 Result := True; 14 end;
得到的结果如下:
{ "Cols":[ { "FieldName":"name", "FieldType":"WideString", "JsonType":"string", "FieldSize":128, "Required":true, "FieldIndex":0 }, { "FieldName":"id", "FieldType":"Integer", "JsonType":"integer", "FieldSize":0, "Required":true, "FieldIndex":1 }, { "FieldName":"xtype", "FieldType":"String", "JsonType":"string", "FieldSize":2, "Required":true, "FieldIndex":2 }, { "FieldName":"uid", "FieldType":"Smallint", "JsonType":"integer", "FieldSize":0, "Required":false, "FieldIndex":3 }, { "FieldName":"info", "FieldType":"Smallint", "JsonType":"integer", "FieldSize":0, "Required":false, "FieldIndex":4 }, { "FieldName":"status", "FieldType":"Integer", "JsonType":"integer", "FieldSize":0, "Required":false, "FieldIndex":5 }, { "FieldName":"base_schema_ver", "FieldType":"Integer", "JsonType":"integer", "FieldSize":0, "Required":false, "FieldIndex":6 }, { "FieldName":"replinfo", "FieldType":"Integer", "JsonType":"integer", "FieldSize":0, "Required":false, "FieldIndex":7 }, { "FieldName":"parent_obj", "FieldType":"Integer", "JsonType":"integer", "FieldSize":0, "Required":true, "FieldIndex":8 }, { "FieldName":"crdate", "FieldType":"TimeStamp", "JsonType":"variant", "FieldSize":0, "Required":true, "FieldIndex":9 }, { "FieldName":"ftcatid", "FieldType":"Smallint", "JsonType":"integer", "FieldSize":0, "Required":false, "FieldIndex":10 }, { "FieldName":"schema_ver", "FieldType":"Integer", "JsonType":"integer", "FieldSize":0, "Required":false, "FieldIndex":11 }, { "FieldName":"stats_schema_ver", "FieldType":"Integer", "JsonType":"integer", "FieldSize":0, "Required":false, "FieldIndex":12 }, { "FieldName":"type", "FieldType":"String", "JsonType":"string", "FieldSize":2, "Required":false, "FieldIndex":13 }, { "FieldName":"userstat", "FieldType":"Smallint", "JsonType":"integer", "FieldSize":0, "Required":false, "FieldIndex":14 }, { "FieldName":"sysstat", "FieldType":"Smallint", "JsonType":"integer", "FieldSize":0, "Required":false, "FieldIndex":15 }, { "FieldName":"indexdel", "FieldType":"Smallint", "JsonType":"integer", "FieldSize":0, "Required":false, "FieldIndex":16 }, { "FieldName":"refdate", "FieldType":"TimeStamp", "JsonType":"variant", "FieldSize":0, "Required":true, "FieldIndex":17 }, { "FieldName":"version", "FieldType":"Integer", "JsonType":"integer", "FieldSize":0, "Required":false, "FieldIndex":18 }, { "FieldName":"deltrig", "FieldType":"Integer", "JsonType":"integer", "FieldSize":0, "Required":false, "FieldIndex":19 }, { "FieldName":"instrig", "FieldType":"Integer", "JsonType":"integer", "FieldSize":0, "Required":false, "FieldIndex":20 }, { "FieldName":"updtrig", "FieldType":"Integer", "JsonType":"integer", "FieldSize":0, "Required":false, "FieldIndex":21 }, { "FieldName":"seltrig", "FieldType":"Integer", "JsonType":"integer", "FieldSize":0, "Required":false, "FieldIndex":22 }, { "FieldName":"category", "FieldType":"Integer", "JsonType":"integer", "FieldSize":0, "Required":false, "FieldIndex":23 }, { "FieldName":"cache", "FieldType":"Smallint", "JsonType":"integer", "FieldSize":0, "Required":false, "FieldIndex":24 } ], "Fields":["name","id","xtype","uid","info","status","base_schema_ver","replinfo","parent_obj","crdate","ftcatid","schema_ver","stats_schema_ver","type","userstat","sysstat","indexdel","refdate","version","deltrig","instrig","updtrig","seltrig","category","cache"], "Data":[ ["sysrscols",3,"S",4,0,0,0,0,0,"2010-04-02 16:59:21",0,0,0,"S",1,1,0,"2010-04-02 16:59:21",0,0,0,0,0,2,0], ["sysrowsets",5,"S",4,0,0,0,0,0,"2010-04-02 16:59:21",0,0,0,"S",1,1,0,"2010-04-02 16:59:21",0,0,0,0,0,2,0], ["sysallocunits",7,"S",4,0,0,0,0,0,"2010-04-02 16:59:21",0,0,0,"S",1,1,0,"2010-04-02 16:59:21",0,0,0,0,0,2,0], ["sysfiles1",8,"S",4,0,0,0,0,0,"2003-04-08 09:13:37",0,0,0,"S",1,1,0,"2003-04-08 09:13:37",0,0,0,0,0,2,0], ["syspriorities",17,"S",4,0,0,0,0,0,"2010-04-02 16:59:22",0,0,0,"S",1,1,0,"2010-04-02 16:59:22",0,0,0,0,0,2,0], ["sysdbfrag",18,"S",4,0,0,0,0,0,"2010-04-02 16:59:21",0,0,0,"S",1,1,0,"2010-04-02 16:59:21",0,0,0,0,0,2,0], ["sysfgfrag",19,"S",4,0,0,0,0,0,"2010-04-02 16:59:21",0,0,0,"S",1,1,0,"2010-04-02 16:59:21",0,0,0,0,0,2,0], ["syspru",21,"S",4,0,0,0,0,0,"2010-04-02 16:59:21",0,0,0,"S",1,1,0,"2010-04-02 16:59:21",0,0,0,0,0,2,0], ["sysbrickfiles",22,"S",4,0,0,0,0,0,"2010-04-02 16:59:21",0,0,0,"S",1,1,0,"2010-04-02 16:59:21",0,0,0,0,0,2,0], ["sysphfg",23,"S",4,0,0,0,0,0,"2010-04-02 16:59:21",0,0,0,"S",1,1,0,"2010-04-02 16:59:21",0,0,0,0,0,2,0], ["sysprufiles",24,"S",4,0,0,0,0,0,"2010-04-02 16:59:21",0,0,0,"S",1,1,0,"2010-04-02 16:59:21",0,0,0,0,0,2,0], ["sysftinds",25,"S",4,0,0,0,0,0,"2010-04-02 16:59:21",0,0,0,"S",1,1,0,"2010-04-02 16:59:21",0,0,0,0,0,2,0], ["sysowners",27,"S",4,0,0,0,0,0,"2010-04-02 16:59:21",0,0,0,"S",1,1,0,"2010-04-02 16:59:21",0,0,0,0,0,2,0], ["sysdbreg",28,"S",4,0,0,0,0,0,"2010-04-02 16:59:21",0,0,0,"S",1,1,0,"2010-04-02 16:59:21",0,0,0,0,0,2,0], ["sysprivs",29,"S",4,0,0,0,0,0,"2010-04-02 16:59:21",0,0,0,"S",1,1,0,"2010-04-02 16:59:21",0,0,0,0,0,2,0], ["sysschobjs",34,"S",4,0,0,0,0,0,"2010-04-02 16:59:21",0,0,0,"S",1,1,0,"2010-04-02 16:59:21",0,0,0,0,0,2,0], ["syslogshippers",39,"S",4,0,0,0,0,0,"2010-04-02 16:59:21",0,0,0,"S",1,1,0,"2010-04-02 16:59:21",0,0,0,0,0,2,0], ["syscolpars",41,"S",4,0,0,0,0,0,"2010-04-02 16:59:21",0,0,0,"S",1,1,0,"2010-04-02 16:59:21",0,0,0,0,0,2,0], ["sysxlgns",42,"S",4,0,0,0,0,0,"2010-04-02 16:59:21",0,0,0,"S",1,1,0,"2010-04-02 16:59:21",0,0,0,0,0,2,0], ["sysxsrvs",43,"S",4,0,0,0,0,0,"2010-04-02 16:59:21",0,0,0,"S",1,1,0,"2010-04-02 16:59:21",0,0,0,0,0,2,0] ] }
可以看到,数据量明显减少,而且并不影响数据的解析。因为Data数组里面的每条记录(也是数组)是和字段信息的顺序一致的。