利用QJSON将FDQuery转成JSON串
服务器要支持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串的更多相关文章
- JSON详解以及可以把javabean转换成json串的json-lib应用
JSON 1. json是什么 它是js提供的一种数据交换格式! 2. json的语法 {}:是对象! 属性名必须使用双引号括起来!单引不行!!! 属性值:null,数值,字符串,数组:使用[]括起来 ...
- json串转化成xml文件、xml文件转换成json串
1.json串转化成xml文件 p=[{"name":"tom","age":30,"sex":"男" ...
- js数组转换成json串 (JSON.stringify)
例如: var giftlist[1490011777] = []; giftlist[1490011777]['id'] = 1490011777; giftlist[1490011777]['na ...
- ios 传递JSON串过去 前面多了个等号
先说下我的问题 后台让我这边把请求的参数弄成一个实体转化成 json 串放body里传给他,当然header也有设置,提前设置好了, 但是后来了解 所谓的把实体转成json串的本质就是先把实体用run ...
- Java 转JSON串
一.JSON (JavaScript Object Notation) 1.轻量级数据交换格式能够替代XML的工作 2.数据格式比较简单, 易于读写, 格式都是压缩的, 占用带宽小(简洁.简单.体积小 ...
- java中LIst转换成Json
List转换成json串 public String getNameListByID(Long Id) { List<Name> nameLists= nameService.select ...
- python json-json.loads()函数中的字符串需要是严格的json串格式,不能包含单引号
先看下json的dumps()和loads()函数的定义 json.dumps():将一个Python对象编码成JSON字符串.把字典对象转换成json串 json.loads():将JSON格式字符 ...
- 将字典或者数组转换成JSON数据或者字符串
将字典或者数组转换成JSON数据或者字符串 源码: NSDictionary+JSON.h 与 NSDictionary+JSON.m // // NSDictionary+JSON.h // Cat ...
- JMeter获取复杂的JSON串中的参数的值
大家好,这篇博文中主要是介绍怎么用JMeter的BeanShell去获取复杂的JSON串中的某个参数的值,这将 便于我们用JMeter做出更完美的自动化测试: 首先有这样一个json串: { &quo ...
随机推荐
- 哈希表(Hash Table)
参考: Hash table - Wiki Hash table_百度百科 从头到尾彻底解析Hash表算法 谈谈 Hash Table 我们身边的哈希,最常见的就是perl和python里面的字典了, ...
- linux学习网站分享
http://www.zhihu.com/question/19895288 http://linux.vbird.org/ 两个linux学习的网页存起来,以后学习.
- select distinct
select distinct select distinct 用于返回表中唯一不同的值. 语法 select distinct 列名称 from 表名称 使用 distinct 关键字 Studen ...
- Android开发之无线遥控器
最近弄了一个UDP/TCP的小东西,主要需要实现的功能如下(服务器端): 1.基于局域网 2.服务器端网络接口为无线与有线 3.服务器端接收到客户端的数据需要模拟按键进行处理 4.开机自启动 5.使用 ...
- HTML5Viewer中如何运行时绑定多数据源
很多报表控件提供HTML5Viewer 支持跨设备的报表系统,当然在很多情况下,一个系统可包含多个报表文件,这些报表的数据有可能均为运行时绑定数据源,那么在html5viewer中对一张报表通过重写W ...
- VPN安装后报错:Reason442 & Error56
VPN安装后一直报错,同样的32位安装包别人安装是正常,自己安装就不正常了,考虑到是自己电脑配置的问题. 经过一番努力,解决了问题,下面就本次解决过程做一个小小的总结. (1)确保VPN Servic ...
- 实现断点续传的FTP下载类(支持多线程多任务下载)
using System; using System.Collections.Generic; using System.Text; using System.Threading; using Sys ...
- Java IO教程
1 Java IO 教程 2 Java IO 概述 3 Java IO: 文件 4 Java IO: 管道 5 Java IO: 网络 6 Java IO: 字节和字符数组 7 Java IO: S ...
- hexo deploy出错的解决方法
.ERROR Deployer not found: git 执行npm install hexo-deployer-git --save .$ hexo d INFO Deploying: git ...
- 面向对象的高级编程&IO编程
1.给类对象绑定的函数,只对这个对象生效, 而对类绑定的对象, 所有的对象都可以调用. 栗子: def set_score(self, score): self.score = score s.set ...