服务器要支持Http协议,打算采用Http+JSON的方式来交换数据。一开始考虑使用superobject,因为以前使用比较多,比较熟悉。

代码如下:

 class function FDQueryToSJSON(aQuery : TFDQuery) : string;

 class function TFDQueryJSONReflect.FDQueryToSJSON(aQuery: TFDQuery): string;
var
sj,aj,sj2,aj2:ISuperObject;
i:Integer;
Fieldtyp,JsonTyp:string;
List:TStringList;
aField : TField;
Fields : string;
begin
// 得到一个JSON对象
sj := SO();
//创建列
aj := SA([]);
List := TStringList.Create;
try
List.Sorted := True; Fields := '{';
for i := to aQuery.FieldCount - do
begin
sj2 := SO();
GetFieldTypeInfo(aQuery.Fields[i],Fieldtyp,JsonTyp); sj2.S[cstFieldName] := aQuery.Fields[i].FieldName;
sj2.S[cstFieldType] := Fieldtyp;
sj2.S[cstJsonType] := JsonTyp;
sj2.I[cstFieldSize] := aQuery.Fields[i].Size;
sj2.B[cstRequired] := aQuery.Fields[i].Required;
sj2.I[cstFieldIndex] := aQuery.Fields[i].Index;
aj.AsArray.Add(sj2);
List.Add(aQuery.Fields[i].FieldName+'='+JsonTyp);
Fields := Fields+aQuery.Fields[i].FieldName+':'+''+',';
end;
Fields := Fields.TrimRight([',']);
Fields := Fields+'}'; sj.O['Fields'] := SO(Fields);
sj.O['Cols'] := aj;
//创建数据集的数据
aQuery.DisableControls;
aQuery.First; aj2 := SA([]);
while not aQuery.Eof do
begin
sj2 := SO();
for i := to List.Count - do
begin
aField := aQuery.Fields.FindField(List.Names[i]); if VarIsNull(aField.Value) then
sj2.O[aField.FieldName] := SO(Null)
else
begin
CreateJsonValueByField(sj2,aField);
end;
end;
aj2.AsArray.Add(sj2);
aQuery.Next;
end; sj.O['Data'] := aj2;
Result := sj.AsString;
finally
List.Free;
aQuery.EnableControls;
end;
end;
 class function CreateJsonValueByField(Json:ISuperObject;Field:TField):Boolean; overload;

 class function TFDQueryJSONReflect.CreateJsonValueByField(Json: ISuperObject;
Field: TField): Boolean;
begin
Result := False;
if (Field Is TDateTimeField) or (Field is TSQLTimeStampField) then
Json.O[Field.FieldName] := SO(Field.AsDateTime)
else if Field is TBlobField then
Json.S[Field.FieldName] := EncodeString(Field.AsString)
else
Json.O[Field.FieldName] := SO(Field.Value);
Result := True;
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得到的结果顺序和我预期是一致的。

代码如下:

 class function FDQueryToQJSON(aQuery : TFDQuery) : string;

 class function TFDQueryJSONReflect.FDQueryToQJSON(aQuery: TFDQuery): string;
var
i:Integer;
Fieldtyp,JsonTyp:string;
List:TStringList;
aField : TField;
aqjsonall, aqjson,aqjson2, aqFields, aqjsonTemp : TQJSON;
begin
aqjsonall := TQJSON.Create;
aqjson := aqjsonall.AddArray('Cols');
List := TStringList.Create;
try
List.Sorted := False; aqFields := aqjsonall.AddArray(cstFields); for i := to aQuery.FieldCount - do
begin
aqjsonTemp := TQJson.Create; GetFieldTypeInfo(aQuery.Fields[i],Fieldtyp,JsonTyp); aqjsonTemp.AddVariant(cstFieldName,aQuery.Fields[i].FieldName);
aqjsonTemp.AddVariant(cstFieldType,Fieldtyp);
aqjsonTemp.AddVariant(cstJsonType,JsonTyp);
aqjsonTemp.AddVariant(cstFieldSize, aQuery.Fields[i].Size);
aqjsonTemp.AddVariant(cstRequired, aQuery.Fields[i].Required);
aqjsonTemp.AddVariant(cstFieldIndex, aQuery.Fields[i].Index); aqjson.Add(aqjsonTemp);
List.Add(aQuery.Fields[i].FieldName+'='+JsonTyp); aqFields.Add.AsString := aQuery.Fields[i].FieldName;
end; //创建数据集的数据
aQuery.DisableControls;
aQuery.First; aqjson2 := aqjsonall.AddArray(cstData); while not aQuery.Eof do
begin
aqjsonTemp := aqjson2.AddArray('DataItem');
for i := to List.Count - do
begin
aField := aQuery.Fields.FindField(List.Names[i]); if VarIsNull(aField.Value) then
aqjsonTemp.Add.AsString := SO(Null).AsString
else
begin
CreateJsonValueByField(aqjsonTemp,aField);
end;
end;
aQuery.Next;
end;
Result := aqjsonall.AsString; finally
List.Free;
aQuery.EnableControls;
aqjsonall.Free;
end;
end;
 class function CreateJsonValueByField(Json:TQJSON;Field:TField):Boolean; overload;

 class function TFDQueryJSONReflect.CreateJsonValueByField(Json: TQJSON;
Field: TField): Boolean;
begin
Result := False;
if (Field Is TDateTimeField) or (Field is TSQLTimeStampField) then
Json.Add.AsString := FormatdateTime('yyyy-MM-dd hh:mm:ss', Field.AsDateTime)
else if Field is TBlobField then
Json.add.AsString := EncodeString(Field.AsString)
else
Json.Add.AsVariant := Field.Value;
Result := True;
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数组里面的每条记录(也是数组)是和字段信息的顺序一致的。

利用QJSON将FDQuery转成JSON串的更多相关文章

  1. JSON详解以及可以把javabean转换成json串的json-lib应用

    JSON 1. json是什么 它是js提供的一种数据交换格式! 2. json的语法 {}:是对象! 属性名必须使用双引号括起来!单引不行!!! 属性值:null,数值,字符串,数组:使用[]括起来 ...

  2. json串转化成xml文件、xml文件转换成json串

    1.json串转化成xml文件 p=[{"name":"tom","age":30,"sex":"男" ...

  3. js数组转换成json串 (JSON.stringify)

    例如: var giftlist[1490011777] = []; giftlist[1490011777]['id'] = 1490011777; giftlist[1490011777]['na ...

  4. ios 传递JSON串过去 前面多了个等号

    先说下我的问题 后台让我这边把请求的参数弄成一个实体转化成 json 串放body里传给他,当然header也有设置,提前设置好了, 但是后来了解 所谓的把实体转成json串的本质就是先把实体用run ...

  5. Java 转JSON串

    一.JSON (JavaScript Object Notation) 1.轻量级数据交换格式能够替代XML的工作 2.数据格式比较简单, 易于读写, 格式都是压缩的, 占用带宽小(简洁.简单.体积小 ...

  6. java中LIst转换成Json

    List转换成json串 public String getNameListByID(Long Id) { List<Name> nameLists= nameService.select ...

  7. python json-json.loads()函数中的字符串需要是严格的json串格式,不能包含单引号

    先看下json的dumps()和loads()函数的定义 json.dumps():将一个Python对象编码成JSON字符串.把字典对象转换成json串 json.loads():将JSON格式字符 ...

  8. 将字典或者数组转换成JSON数据或者字符串

    将字典或者数组转换成JSON数据或者字符串 源码: NSDictionary+JSON.h 与 NSDictionary+JSON.m // // NSDictionary+JSON.h // Cat ...

  9. JMeter获取复杂的JSON串中的参数的值

    大家好,这篇博文中主要是介绍怎么用JMeter的BeanShell去获取复杂的JSON串中的某个参数的值,这将 便于我们用JMeter做出更完美的自动化测试: 首先有这样一个json串: { &quo ...

随机推荐

  1. Struts2配置Result(Struts2_result)

    一.概要 二.常用四种类型的配置 Struts.xml <?xml version="1.0" encoding="UTF-8" ?> <!D ...

  2. select下拉框插件(转)

    <!doctype html> <html> <head> <meta charset="UTF-8"> <title> ...

  3. sql server sql语句导入数据到execl2007中

    insert into OPENROWSET('Microsoft.ACE.OLEDB.12.0','Excel 12.0;Database=C:\c.xlsx','select 字段1,字段2 FR ...

  4. oracle笔记

    一.sql*plus常用命令 (1)connect 用法:conn 用户名/密码@网络服务名[as sysdba/sysoper] 当特权用户连接时,必须带上as sysdba或是as sysoper ...

  5. biweb添加新的模块

    1.例如添加一个新闻模块,首先去纯净的项目的根目录复制出一个news文件夹到项目外 2.打开dreamweaver, 编辑 ->查找和替换 例如 新模块 叫 我的新闻,英文名叫mynews,则进 ...

  6. WordPress网站搭建

    . 1.进入 var/www/html中放入里的文件 2.. 安装http php php-sql [root@jw38 yum.repos.d]# systemctl restart httpd.s ...

  7. sessionStorage & localStorage & cookie

    sessionStorage & localStorage & cookie 概念 html5中的Web Storage包括了两种存储方式:sessionStorage和localSt ...

  8. Android ADB 用法

    adb  全称是 Android Debug Bridge, 就是起到调试桥的作用. 用来操作android设备的 阅读目录 adb 有什么用 借助adb工具, 我们可以管理设备或手机模拟器的状态,  ...

  9. Html.DropDownList

    //获取直属父级列表 var parents = _MemberEditDTOService.GetParents(); var parentsItems = parents.Result.Selec ...

  10. Chome v42 支持Java

    从ver42开始,Chrome默认禁用了NPAPI.可以去chrome://flags/#enable-npapi开启,但是google很有可能在9月从代码中彻底移除NPAPIFirefox也有这个意 ...