#1 2016-12-09 14:24:13

donaldshimoda
Member
From: Argentina
Registered: 2016-12-09
Posts: 25
Website

How to parse a simple JSON text and produce JSON

I need to understand how to do this with mormot this (the code must be compatible with delphi and lazarus)

parse a JSON object (Respuesta string)

var
  soDetectado, soaMessage : SuperObject;
begin
    soDetectado := SuperObject.so(Respuesta);
    Detectado.IdTransaccion    :=  soDetectado[strListaDetectados+'[0].IdTransaccion'].AsString;
    Detectado.Identificador    :=  soDetectado[strListaDetectados+'[0].Identificador'].AsString;
    for soaMessage in soDetectado[strListaDetectados+'[0].Mensajes'] do
    begin
          NewMessage               := Detectado.Mensajes.Add;
          NewMessage.Mensaje       := soaMessage['Mensaje'].AsString;
          NewMessage.IDTipoMensaje :=(soaMessage['IdTipoMensaje'].AsInteger);
     end;
end;

populate a JSON object

    soEstructura  := XSuperObject.TSuperObject.Create;
    soEstructura.S['Llave'] := 'xxxxx';
    soEstructura.I['FechaRegistro'] := traducirFecha(now);
    with soEstructura.O['Informacion'] do
    begin
      S['Denominacion']       := lSomeDataset.FieldByName('DENOMINACION').AsString.ToUpper;
      S['Departamento']       := lSomeDataset.FieldByName('DEPARTAMENTO').AsString.ToUpper;
    end;
    with soEstructuraEstacion.O['Estructura'] do
    begin
      with O['Software'] do
      begin
        S['Empresa']          := 'SOME';
     end;
   end;
   aPos := 0;
      while (not lRFID.EOF) do
      begin
        with A['RFID'].O[aPos].AsObject do
        begin
          S['Codigo']      := lRFID.FieldByName('CODIGO').AsString.ToUpper;
        end;
        lRFID.Next;
        Inc(aPos);
      end;

Im using superobjects and Xsuperobject but is not fully compatible with freepascal right now.

Thanks for any point to a sample or tutorial.

Best regards.
P.S. I never user mormot before.

Offline

#2 2016-12-09 18:59:57

jbroussia
Member
From: France
Registered: 2011-04-09
Posts: 74

Re: How to parse a simple JSON text and produce JSON

You should find your answers here: http://synopse.info/forum/viewtopic.php?id=1631

Offline

#3 2016-12-09 19:42:01

donaldshimoda
Member
From: Argentina
Registered: 2016-12-09
Posts: 25
Website

Re: How to parse a simple JSON text and produce JSON

jbroussia wrote:

You should find your answers here: http://synopse.info/forum/viewtopic.php?id=1631

Thank you!

Offline

#4 2016-12-09 21:14:29

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,606
Website

Re: How to parse a simple JSON text and produce JSON

See the documentation about this point:
http://synopse.info/files/html/Synopse% … ml#TITL_80

Offline

#5 2016-12-22 12:47:52

donaldshimoda
Member
From: Argentina
Registered: 2016-12-09
Posts: 25
Website

Re: How to parse a simple JSON text and produce JSON

I start migrating on my test it:

Work fine on Delphi,

fails in windows/linux i386 (fpc 3.1 + lazarus 1.7)

unit SynCommons;

{$ifdef CPUINTEL}
procedure TestIntelCpuFeatures;
var regs: TRegisters;
begin
  regs.edx := 0;
  regs.ecx := 0;
  GetCPUID(1,regs);
  PIntegerArray(@CpuFeatures)^[0] := regs.edx;
  PIntegerArray(@CpuFeatures)^[1] := regs.ecx;
  GetCPUID(7,regs);
  PIntegerArray(@CpuFeatures)^[2] := regs.ebx;
  PByteArray(@CpuFeatures)^[12] := regs.ecx;
end;
{$endif CPUINTEL}   

SynCommons.pas(61334,3) Error: Identifier not found "GetCPUID"

Work perfect in linux ARM (fpc 3.1 + lazarus 1.7)

Any easy fix? As i need right now on linux/arm and win32 im not worried, but want to know if will be fixed in a near future.

Best regards.

Last edited by donaldshimoda (2016-12-22 13:07:44)

Offline

#6 2017-02-13 12:11:07

donaldshimoda
Member
From: Argentina
Registered: 2016-12-09
Posts: 25
Website

Re: How to parse a simple JSON text and produce JSON

donaldshimoda wrote:

Any easy fix? As i need right now on linux/arm and win32 im not worried, but want to know if will be fixed in a near future.

Best regards.


Hi , now i need it working on linux 386 and X64. How to fix this problem? latest version takes from the repos.

Best regards.

Offline

Board footer

Powered by FluxBB