一、生成如下格式:

1 生成的格式如下:
2   {
3   "Status":0,
4   "Msg":"成功"
5   "Data":["2001","5","13939","麦西恩原味卷饼270g","70070703","上海谷丹工","2001","6","13940","麦西恩全麦卷饼270g","70070703","上海谷丹工"],
6   }

Code:

begin

    Jo.Clear;
     try
    
    oQuery.SQL.Text:=sqlstr;
    oQuery.Open();
     oQuery.First;
     fdbh:=oQuery.RecordCount;
     jo.Add('cmdIndex').AsInteger:=99;
     joitem := Jo.Add('Data',jdtArray);
    while not oQuery.Eof do
    begin

      joitem.add('fdbh').AsString := oQuery.FieldByName('fdbh').Value;
      joitem.add('sp_id').AsString := oQuery.FieldByName('sp_id').Value;
      joitem.add('pluid').AsString := oQuery.FieldByName('pluid').Value;
      joitem.add('pluname').AsString := oQuery.FieldByName('pluname').Value;
      joitem.add('spfl').AsString := oQuery.FieldByName('spfl').Value;
      joitem.add('supname').AsString := oQuery.FieldByName('supname').Value;
      oQuery.Next;
    end;
   sfLogger.logMessage(jo.AsJson);
  finally
    
  end;

二、生成如下格式(最常用的):

 

 {
   "Status": true,
    "Message": "Test",
  "Data":[
    {
      "fdbh":"2001",
      "sp_id":"5",
      "pluid":"13939",
      "pluname":"麦西恩原味卷饼270g",
      "spfl":"70070703",
      "supname":"上海谷丹"
    },
    {
      "fdbh":"2001",
      "sp_id":"6",
      "pluid":"13940",
      "pluname":"麦西恩全麦卷饼270g0",
      "spfl":"70070703",
      "supname":"上海谷丹"
    }
  ]
}
   Jo.Add('Status').AsInteger := 0;
Jo.Add('Message').Asstring := "Test";

    joitem := Jo.Add('Data', jdtArray);
    while not oQuery.Eof do
    begin
      with joitem.Add do
      begin
        add('fdbh').AsString := oQuery.FieldByName('fdbh').Value;
        add('sp_id').AsString := oQuery.FieldByName('sp_id').Value;
        add('pluid').AsString := oQuery.FieldByName('pluid').Value;
        add('pluname').AsString := oQuery.FieldByName('pluname').Value;
        add('spfl').AsString := oQuery.FieldByName('spfl').Value;
        add('supname').AsString := oQuery.FieldByName('supname').Value;
      end;
      oQuery.Next;
    end;

 

posted on 2021-02-18 16:32  EEEEEEEEEEEEEEEEEEE  阅读(56)  评论(0编辑  收藏  举报