利用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 ...
随机推荐
- Git和.gitignore
http://blog.csdn.net/cscmaker/article/details/8553980 在git中如果想忽略掉某个文件,不让这个文件提交到版本库中,可以使用修改根目录中 .giti ...
- NPOI的使用Excel模板导出
private string ExportScMeeting(DataTable source) { string templateFile = Server.MapPath(@"Excel ...
- html小知识点汇总(浏览器导航上显示图标、div无高度时试着清除浮动、文字环绕图片、字体加粗、div按百分比分、已有的不合适的class,针对特定的标签进行修改)
1.新点击的网页,在浏览器导航上显示图标: 像这种效果: <head> <meta charset="UTF-8"> <meta name=" ...
- SSIS数据转换后数值总数差异过大
之前做过一个项目,犯了一个小错误,写出来给大家分享一下,以防大家出同样的错误. 做了一个ETL包,对货品的销售额进行数据转换,字符型 --〉 浮点型: 之后对销售额进行求和,在测试数据结果时发现与销售 ...
- SQLServer字符操作
1.CHARINDEX('A',‘VALUE’) result:2 style:PATINDEX(varchar,varchar) 解释:A在字符串VALUE的位置次序. 2.PATINDEX( ...
- 报错记录:getOutputStream() has already been called for this response
仅作记录:参考文章:http://www.blogjava.net/vickzhu/archive/2008/11/03/238337.html 报错信息: java.lang.IllegalStat ...
- 编写我的第一个CGI代码——python学习
在编程学习网站学习Python语言,学习到cgi编程章节遇到了一些小问题,课程介绍的为linux环境的Apache配置方法,具体如下: [linux环境配置方法:] 在进行CGI编程前,确保您的Web ...
- css样式之 direction
今天看到 direction:rtl.一时有点发傻. 其实就是文本读取顺序.默认是ltr从左向右读.rtl是从右向左读取.
- Oracle一个事务中的Insert和Update执行顺序
今天碰到了一个奇怪的问题,是关于Oracle一个事务中的Insert和Update语句的执行顺序的问题. 首先详细说明下整个过程: 有三张表:A,B,C,Java代码中有一段代码是先在表A中插入一条数 ...
- Sublime Text 2 代码片断
原文:Snippets 不管是在编码,还是写畅销书,你都可能会需要一遍又一遍的用到一些文本的小片断.使用片断来结束这种单调无聊的码字吧,片断是一种智能的模板,它能在合适的上下文中插入你需要的文本内容. ...