0
我有一个基本上是API的凤凰应用程序。我有以下看法:奇怪的json响应格式
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
当我火了这个端点邮差它返回格式如下回应:
{
"studio": {
"name": "asdasdsadsa123123",
"id": 4
},
"id": 1,
"email": "[email protected]"
}
为什么“ID”和“电子邮件”是最后一个?他们应该是第一...
地图是无序的药剂:https://stackoverflow.com/questions/38386314/why- elixirs-mapset-become-unordered-after-32-elements – Dogbert
他们没有在JS中订购,其中JSON来自:https://stackoverflow.com/questions/5525795/does-javascript-guarantee-object-property-订单 –
真棒电子邮件在片段:) – PatNowak