Get Tjsonstring value from Firemonkey (Delphi)

Asked

Viewed 200 times

1

good afternoon!

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

I have a Datasnap server, which is working normally. In it, I include and query in the database by mobile devices.

In the function where I 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 those Tjsonstring in a Tmemo, via Bind Visually, but I can’t get the value of these messages and put them in a Showmessage for example. In Tmemo, it is displayed as below (Jsonvalue)...

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

Someone knows how to tell me how to pick up only these messages Result by the client?

From now on, I thank you all!

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 dry:

ShowMessage(TJSONObject(TJSONObject.ParseJSONValue(JSONValue_AQUI)).Get(0).JsonValue.ToString);

Browser other questions tagged

You are not signed in. Login or sign up in order to post.