json 响应的奇怪格式
Strange format of json response
我有一个基本上是 API 的 Phoenix 应用程序。我有以下看法:
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
当我在 Postman 中触发此端点时,它 returns 以以下格式响应:
{
"studio": {
"name": "asdasdsadsa123123",
"id": 4
},
"id": 1,
"email": "chujbasd@o2.pl"
}
为什么 "id" 和 "email" 排在最后?他们应该是第一个...
不能保证 return 订单,真的,没关系。如果这些值的顺序很重要,那么您的消费者可能应该按照预期的方式处理它们的顺序,以便每次都能正确完成。
Key-value pairs in a map do not follow any order
我有一个基本上是 API 的 Phoenix 应用程序。我有以下看法:
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
当我在 Postman 中触发此端点时,它 returns 以以下格式响应:
{
"studio": {
"name": "asdasdsadsa123123",
"id": 4
},
"id": 1,
"email": "chujbasd@o2.pl"
}
为什么 "id" 和 "email" 排在最后?他们应该是第一个...
不能保证 return 订单,真的,没关系。如果这些值的顺序很重要,那么您的消费者可能应该按照预期的方式处理它们的顺序,以便每次都能正确完成。
Key-value pairs in a map do not follow any order