如何将JSON响应转换为String并将其与字符串进行比较

问题描述 投票:0回答:1

我正在尝试获取请求的POST数据,并将其与预期的数据字符串进行比较,但它不起作用,不确定这里出了什么问题:

   var PostData = '"{\\\"filter\\\":{\\\"operator\\\":\\\"and\\\"}}"';     
    expect(PostData).toMatch(JSON.stringify(message.params.request.postData));

我的期望每次都会因以下错误而失败:

Expected '"{\"filter\":{\"operator\":\"and\"}}"' to match '"{\"filter\":{\"operator\":\"and\"}}"'
javascript java node.js jasmine protractor
1个回答
0
投票
尝试使用:

expect(PostData).toMatch(JSON.stringify(JSON.parse(message.params.request.postData)));

© www.soinside.com 2019 - 2024. All rights reserved.