Ver Mensaje Individual
  #1  
Antiguo 18-10-2022
Avatar de StartKill
StartKill StartKill is offline
Miembro
 
Registrado: ene 2004
Posts: 299
Reputación: 21
StartKill Va por buen camino
uLkJSON con Delphi XE

Saludos al foro
A los años que me acerco al Club del conocimiento.

Tengo un aplicativo hecho en Delphi XE y necesito implementar una rutina en JSON, para ello estoy utilizando la unit uLkJSON.

Mas logro llevar al CDS con las tildes

Código Delphi [-]
//En un memo tengo estas líneas:

[
  {
    "id": 1,
   "nombre": "Pepíto Conejo",
    "edad": 25,
    "carnet": 1
  },
  {
    "id": 2,
    "nombre": "Ana Barbéro",
    "edad": 90,
    "carnet": 0
  }
]

procedure TForm24.Button1Click(Sender: TObject);
var
   sJSON: string;
   jl: TlkJSONlist;
   ja: TlkJSONobject;
   I: Integer;
begin
   ClientDataSet1.Open;
   ClientDataSet1.EmptyDataSet;
   sJSON := Memo1.Lines.Text;

   jl := TlkJSON.ParseText(sJSON) as TlkJSONlist;
   for I := 0 to jl.Count - 1 do
   begin
      ja := jl.child[i] as TlkJSONobject;
      ClientDataSet1.Insert;
      ClientDataSet1id.AsString := ja.Field['id'].Value;
      ClientDataSet1nombre.AsString := ja.getString('nombre');
       ClientDataSet1edad.AsInteger := ja.Field['edad'].Value;
      ClientDataSet1carnet.AsInteger := ja.Field['carnet'].Value;
      ClientDataSet1.Post;
   end;
end;

A la espera de su ayuda

Your friend

StartKill
Lima-Perú
Responder Con Cita