如何比较两个JSON响应中存在的字段并验证它?
我需要比较响应1中出现的所有国家 /地区也应在Response2中存在。 那么,我该如何从回答中夺取所有国家并验证呢? 我尝试在Arraylist中存储国家,但无法验证它。
JSON响应1:
{
"plan": {
"program": "gtr",
"syter": "yes"
},
"Map": {
"List": [
{
"id": "tyt6577",
"proxy": "ENABLED",
"type": "BENEFIT",
"country": "us",
"triag": null
},
{
"id": "yyaqtf6327",
"proxy": "ENABLED",
"type": "BENEFIT",
"country": "aus",
"triag": null
},
{
"id": "676hwjsgvhgv",
"proxy": "ENABLED",
"type": "BENEFIT",
"country": "rus",
"triag": null
},
{
"id": "676hsdhgv",
"proxy": "ENABLED",
"type": "BENEFIT",
"country": "spa",
"triag": null
},
{
"id": "623ujhhgv",
"proxy": "ENABLED",
"type": "BENEFIT",
"country": "cha",
"triag": null
}
]
}
}
JSON响应2:
[
{
"id": "tyt6577",
"proxy": "ENABLED",
"type": "BENEFIT",
"country": "rus",
"triag": null
},
{
"id": "yyaqtf6327",
"proxy": "ENABLED",
"type": "BENEFIT",
"country": "spa",
"triag": null
},
{
"id": "676hwjsgvhgv",
"proxy": "ENABLED",
"type": "BENEFIT",
"country": "us",
"triag": null
},
{
"id": "676hsdhgv",
"proxy": "ENABLED",
"type": "BENEFIT",
"country": "aus",
"triag": null
},
{
"id": "623ujhhgv",
"proxy": "ENABLED",
"type": "BENEFIT",
"country": "cha",
"triag": null
}
]
I need to compare all the countries present in Response1 should be present in Response2 also.
So How Can I take all the countries from both the responses and validate?
I tried on storing country in ArrayList but not able to validate it.
Json Response 1:
{
"plan": {
"program": "gtr",
"syter": "yes"
},
"Map": {
"List": [
{
"id": "tyt6577",
"proxy": "ENABLED",
"type": "BENEFIT",
"country": "us",
"triag": null
},
{
"id": "yyaqtf6327",
"proxy": "ENABLED",
"type": "BENEFIT",
"country": "aus",
"triag": null
},
{
"id": "676hwjsgvhgv",
"proxy": "ENABLED",
"type": "BENEFIT",
"country": "rus",
"triag": null
},
{
"id": "676hsdhgv",
"proxy": "ENABLED",
"type": "BENEFIT",
"country": "spa",
"triag": null
},
{
"id": "623ujhhgv",
"proxy": "ENABLED",
"type": "BENEFIT",
"country": "cha",
"triag": null
}
]
}
}
Json Response 2:
[
{
"id": "tyt6577",
"proxy": "ENABLED",
"type": "BENEFIT",
"country": "rus",
"triag": null
},
{
"id": "yyaqtf6327",
"proxy": "ENABLED",
"type": "BENEFIT",
"country": "spa",
"triag": null
},
{
"id": "676hwjsgvhgv",
"proxy": "ENABLED",
"type": "BENEFIT",
"country": "us",
"triag": null
},
{
"id": "676hsdhgv",
"proxy": "ENABLED",
"type": "BENEFIT",
"country": "aus",
"triag": null
},
{
"id": "623ujhhgv",
"proxy": "ENABLED",
"type": "BENEFIT",
"country": "cha",
"triag": null
}
]
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这对你有用
This would work for you