邮递员响应以不同的顺序响应来自请求的控制台日志响应 [英] Postman response in different order to console log response from request

查看:72
本文介绍了邮递员响应以不同的顺序响应来自请求的控制台日志响应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当使用 Postman 测试 API 请求时,我得到的响应是无序的,这正是我想要的,即:

When using Postman to test an API a request, the response i get is unordered, which is what I want, i.e.:

}
  "23": "Kevin",
  "2": "James",
  "12": "Michael"
}

但是,当我记录响应时,它会自动将其排序为:

However, when I log the response, it automatically sorts it to:

}
  "2": "James",
  "12": "Michael",
  "23": "Kevin"
}

我收到了承诺中的回复:

I am getting the response in a promise:

return this.client.post('/url', data)
      .then(response => {
        console.log('api response: ', response);

无论如何我可以阻止响应的排序,以便我可以根据需要呈现数据?我不确定数据的顺序在哪里或为什么不同.

Is there anyway I can prevent the ordering of the response so I can render the data as desired? I am not sure where, or why the order of the data is different.

任何帮助将不胜感激!

推荐答案

您不能也不应该依赖 JSON 对象中元素的顺序.

You cannot and should not rely on the ordering of elements within a JSON object.

来自 http://www.json.org/

对象是一组无序的名称/值对

An object is an unordered set of name/value pairs

因此,JSON 库可以按照他们认为合适的方式自由地重新排列元素的顺序.这不是错误.

As a consequence, JSON libraries are free to rearrange the order of the elements as they see fit. This is not a bug.

这篇关于邮递员响应以不同的顺序响应来自请求的控制台日志响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆