Delphi (tokyo) to JSON type RESPONSE only enters the last data value "T"

Asked 1 years ago, Updated 1 years ago, 111 views

objFind := TJSONObject.Create; objFind1 := TJSONArray.Create; objFind4 := TJSONObject.Create; objFind3 := TJSONArray.Create; objFind2 := TJSONObject.Create;

      With nxQuery2.Create(self) do
      begin
        try
          Database := nxDatabase1;
          for I := 0 to nxQuery1.FieldByName('CNT').AsInteger - 1 do
          begin
            SQL.Text := ' SELECT A.* , B.NAME PET_NAME                                 '+#13+
                        '       '       ,B.SNO PET_SNO                                         '+#13+
                        ' ' FROM   HOSPPET A, PET B                                      '+#13+
                        ' ' WHERE  A.STATE   = 7                                         '+#13+
                        '   '   AND  A.TERM_NO = :TERM_NO                                  '+#13+
                        '   '   AND  A.PET_NO  = B.SNO                                     '+#13;
            nxQuery2.ParamByName('TERM_NO').AsInteger := nxQuery1.FieldByName('SNO').AsInteger;
            nxQuery2.open;
            if nxQuery2.RecordCount > 0 then
            begin
              objFind4.AddPair('termNo'     ,TJSONNumber.Create(nxQuery1.FieldByName('SNO').AsInteger));
              objFind4.AddPair('termRegCnt' ,TJSONNumber.Create(nxQuery1.FieldByName('CNT').AsInteger));
              objFind4.AddPair('termName'   ,nxQuery1.FieldByName('TERM_NAME').AsString);
              for j := 0 to nxQuery2.RecordCount - 1 do
              begin
                objFind2.AddPair('petname',nxQuery2.FieldByName('PET_NAME').AsString);
                objFind2.AddPair('test2','34');
                objfind3.Add(objfind2);
                nxQuery2.Next;
              end;
              objFind4.AddPair('termRegList',objFind3);
              objFind1.Add(objFind4);
            end;
            nxQuery1.Next;
          end;
          Result.AddPair('code',TJSONNumber.Create(200));
          Result.AddPair('cmd' ,api_name);
          Result.AddPair('msg' ,objFind1);
        finally
          free;
        end;

      end;

If you run it with the coding as above, it comes out as below. Weissource is a source that rotates the FOR door from 1 to 6 outside and sprinkles the name when it is the same as TERM_NO on the DB. The reason why it consists of two large JSONARRAYs is because there is a TERM_NO called 2,6, and the reason why there are three data on the inside REGLIST is because the ROW on the DB is three lines. There are still a lot of things that need to be revised Why does the inside ROW data value show only the data named 'Mano' corresponding to the last 6?

}

json delphi

2022-09-22 18:45

1 Answers

It's a self-answer. I have to do OBJECT and ARRAY create on each one Thank you


2022-09-22 18:45

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.