浏览代码

* Auto-detect JSON type

michael 6 年之前
父节点
当前提交
e2494de422
共有 1 个文件被更改,包括 9 次插入1 次删除
  1. 9 1
      packages/fcl-db/jsondataset.pas

+ 9 - 1
packages/fcl-db/jsondataset.pas

@@ -332,7 +332,7 @@ type
     // Format JSON date to from DT for Field F
     // Format JSON date to from DT for Field F
     function FormatDateTimeField(DT : TDateTime; F: TField): String; virtual;
     function FormatDateTimeField(DT : TDateTime; F: TField): String; virtual;
     // Create fieldmapper. A descendent MUST implement this.
     // Create fieldmapper. A descendent MUST implement this.
-    Function CreateFieldMapper : TJSONFieldMapper; virtual; abstract;
+    Function CreateFieldMapper : TJSONFieldMapper; virtual;
     // If True, then the dataset will free MetaData and FRows when it is closed.
     // If True, then the dataset will free MetaData and FRows when it is closed.
     Property OwnsData : Boolean Read FownsData Write FOwnsData;
     Property OwnsData : Boolean Read FownsData Write FOwnsData;
     // set to true if unknown field types should be handled as string fields.
     // set to true if unknown field types should be handled as string fields.
@@ -1569,6 +1569,14 @@ begin
     Result:=FormatDateTime(ptrn,DT);
     Result:=FormatDateTime(ptrn,DT);
 end;
 end;
 
 
+function TBaseJSONDataSet.CreateFieldMapper: TJSONFieldMapper;
+begin
+  if FRowType=rtJSONArray then
+    Result:=TJSONArrayFieldMapper.Create
+  else
+    Result:=TJSONObjectFieldMapper.Create;
+end;
+
 function TBaseJSONDataSet.GetFieldData(Field: TField; Buffer: TDatarecord): JSValue;
 function TBaseJSONDataSet.GetFieldData(Field: TField; Buffer: TDatarecord): JSValue;
 
 
 var
 var