我正在做一个API调用,将返回JSON在身体和我想比较JSON对象与字符串。我怎样才能做到这一点?如何将json对象与字符串进行比较?
API以下JSON对象res.body
回报:
{
"name": "tenant_tree",
"documents": [
{
"tags": [],
"scope": "all",
"tenant_id": "0",
"id": "9dd2c5a5-2de2-4ac8-b195-04290f83b6fb",
"version": 1,
"description": "",
"name": "0",
"grouping": "",
"perm_read": "all",
"perm_write": "all",
"version_author": "dg",
"version_date": 1470324147050,
"is_current": true,
"dependencies_guid": [""],
"dependencies_name": [""],
"display_name": "system"
},
}
我想比较像expect(res.body).toMatch('"name": "0"');
但这种失败。
嗨@alecxe'JSON.parse(res.body)'给我出错'意外标记O',我尝试'JSON.stringify(res.body)'这使我的错误: '未定义为等于0' – ssharma