[英]How to parse json data and differenciate value required through java script
我有具有類似變量的json數據,我正在從中獲取所需的id值。 我嘗試了多種格式來檢查/驗證數據,但是由於可用的變量相同,我無法檢索所需的解決方案。
[
{
"id": "",
"email": ,
"name": "",
"phone": "",
"shippingAddress": {
"address1": "",
"city": ,
"country": ,
"postalCode": ,
"state":
},
"billingAddress": {
"address1": "",
"city": "",
"country": ,
"postalCode": ,
"state": ""
}
},
{
"id": "",
"email": ,
"name": "",
"phone": "",
"shippingAddress": {
"address1": ,
"city": ,
"country": ,
"postalCode": ,
"state":
},
"billingAddress": {
"address1": " ",
"city": "",
"country": "",
"postalCode": "",
"state": ""
}
}]
我嘗試了類似的算法。
for (var i=0; i<jsonData.length; i++){
tests["Checking shippingAddress"] = jsonData.shippingAddress.address == " Constitution ";
}
我在Postman for Api中進行自動化,因此api具有具有相同變量的json數據。當具有單個數據時,代碼可以正常工作。
您可能對如何遍歷數據有疑問。
for (var i=0; i < jsonData.length; i++){
tests["Checking shippingAddress"] = jsonData[i].shippingAddress.address === " Constitution ";
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.