新的放心
我有像这样的json响应
{
"queryPath": "/api/",
"nId": "f084f5ad24fcfaa9e9faea0",
"statusCode": 707
"statusMessage": "Success",
"results": {
"data": [
{
"id": "10248522500798",
"capabilities": [
"men",
"women"
],
"name": "errt2"
},
{
"id": "418143778",
"capabilities": [
"dog",
"cat"
],
"name": "Livin"
}
]
}
}
字符串类型="男人" 使用放心我需要检查具有功能数组值的类型值
[
"men",
"women"
]
和
"capabilities": [
"dog",
"cat"
]
If the type value `men` not contains in any of the capabilities i need to raise error..how it is possible?
我使用了以下代码。但是它不起作用。其他方式??
body("results.data.capabilities", hasItems(type));
收到错误
Expected: (a collection containing "men")
Actual: [[ men,women
], [dog, cat]]
答案 0 :(得分:0)
问题是你的jsonPath
function inside_out(folder) {
var typebox = document.getElementById("typebox");
var typeboxJQS = $('#typebox');
var Loader = document.getElementById("thumbnail_loader");
var hr = new XMLHttpRequest();
hr.open("POST", "json_type_data.php", true);
hr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
hr.onreadystatechange = function() {
if (hr.readyState == 4 && hr.status == 200) {
var d = JSON.parse(hr.responseText);
typebox.innerHTML = "";
var temp = '';
typeboxJQS.fadeOut();
for (var o in d) {
if (d.hasOwnProperty(o) && d[o].hasOwnProperty('src') && d[o].src !== '') {
temp += "<div class='typebox'><img id='typeImg' width='30px' height='30px' src=" + d[o].src + "></div>";
}
}
typebox.innerHTML = temp;
typeboxJQS.fadeIn();
}
};
hr.send("folder=" + folder);
}
指向两个“功能”数组,因为它们嵌套在JSON的同一级别。如果您可以可靠地期望第一个“capabilities”数组包含“men”,那么您可以在jsonPath中指定第一个“功能”,如下所示:
results.data.capabilities