如何比较具有不同顺序元素的 Json 数组

QA *_*ing 5 java arrays collections json

我有 2 个 API 响应并将它们转换为 Json 数组。当我将 2 个 json 转换为键值对映射时,值的顺序不同,无法在 2 个 API 响应之间执行比较。

来自 API 1 的 JsonArray:

[
 {
  "employeeSalutation": null,
  "EmployeeName": "Example",
  "EmployeeCode": "SAA",
  "Zip": 12345,
  "DepartmentName": "Social science",
  "EmployeeAddress": "123 st",
  "StateCode": 9,
  "updatedDate": "2018-01-22T03:48:43.59",
  "EmployeeId": 1257
 }
]
Run Code Online (Sandbox Code Playgroud)

API 2 中的 Json 数组:

[
 {
  "Emp_Name": "Example",
  "emp_Sal": null,
  "Dept_Name": "Social science",
  "Emp_addr": "123 st",
  "Zip": "12345",
  "Stat_cd": 9,
  "Emp_id": 1257,
  "upd_d": "2018-01-22 03:48:43.59",
  "Emp_Code": "SAA"
 }
]
Run Code Online (Sandbox Code Playgroud)

我将 2 个 Json 数组转换为键值对映射,其中 EmployeeId 作为数组 1 中的键,Emp_id 作为数组 2 中的键。当我比较 2 个映射时,映射中值的顺序不同并且失败。

如何比较2个API,保证2个api中每个元素的值匹配。

Ahm*_*ETI 0

JSONAssert图书馆对于此类任务非常方便。

这是很好的教程有关如何使用它的

我希望它对你有帮助。