Get value from a TJSONString by Firemonkey (Delphi)

1

Good afternoon!

I have a problem and I would like to see if you can help me.

I have a DataSnap server, which is working normally. In it, I add and query the database by mobile devices.

In the function where I make the register, it is configured like this ...

function TSM.updateClientes(TObjJSON: TJSONObject): TJSONValue;
var
vCliente: TCliente;
begin
  vCliente:=TJson.JsonToObject<TCliente>(TObjJSON.ToJSON);
  try
    tbUsuarios.Open;

    if not (tbUsuarios.Locate('email', vCliente.Email,[])) then
      begin
        tbUsuarios.Append;
        tbUsuarios.FieldByName('nome').AsString:=vCliente.Nome;
        tbUsuarios.FieldByName('email').AsString:=vCliente.Email;
        tbUsuarios.FieldByName('login').AsString:='@'+vCliente.Login;
        tbUsuarios.FieldByName('senha').AsString:=Encode64(vCliente.Senha, IndyTextEncoding_UTF8);
        tbUsuarios.FieldByName('data_cadastro').AsDateTime:=Now;
        tbUsuarios.Insert;
        Result:=TJSONString.Create('Cadastro realizado com sucesso.');
      end
    else
      begin
        Result:=TJSONString.Create('Email já cadastrado.');
      end;

  finally
    tbUsuarios.Close;
    VCliente.Free;
  end;
end;

I can print these TJSONString in TMemo , via Bind Visually , but I can not get the value of those messages and put < ShowMessage for example. In TMemo, it is displayed as below (JSONValue) ...

{
 "result":
 [
  "Cadastro realizado com sucesso."
 ]
}

Does anyone know how to get the results from the client?

Thanks in advance!

    
asked by anonymous 05.09.2018 / 20:45

1 answer

1

It would be something like:

    var
      vJson: String;
      vObjeto: TJSONObject;
    begin
      vObjeto := TJSONObject.ParseJSONValue(JSONValue_AQUI) as TJSONObject;
      vJson := vObjeto.Get(0).JsonValue.ToString;
      vObjeto.Free; 
    end;

Or more wiped:

ShowMessage(TJSONObject(TJSONObject.ParseJSONValue(JSONValue_AQUI)).Get(0).JsonValue.ToString);
    
05.09.2018 / 21:40