Ich habe eine Phoenix App, die im Grunde API ist. Ich habe die folgende Ansicht:Seltsames Format von JSON Antwort
defmodule TattooBackend.Web.API.V1.AccountView do
use TattooBackend.Web, :view
alias TattooBackend.Repo
def render("my_account.json", %{account: account}) do
account = account |> Repo.preload(:studio)
studio = account.studio
%{
id: account.id,
email: account.email,
studio: %{
id: account.studio.id,
name: account.studio.name
}
}
end
end
Wenn ich Feuer diesen Endpunkt in Postman es Antwort in folgendem Format zurück:
{
"studio": {
"name": "asdasdsadsa123123",
"id": 4
},
"id": 1,
"email": "[email protected]"
}
Warum die "id" und "E-Mail" sind zuletzt? Sie sollten zuerst ...
Karten ungeordnet sind in Elixir: https://stackoverflow.com/questions/38386314/why- elixirs-mapset-unordered-after-32-elements – Dogbert
Sie sind auch nicht in JS angeordnet, wo JSON herkommt: https://stackoverflow.com/questions/5525795/does-javascript-guarantee-object-property- Bestellung –
Super E-Mail im Snippet :) – PatNowak