我正在用MockMvc进行一些测试,我想验证JSON响应的结构。具体来说,我希望确保属性的键存在,并且该值具有某种类型或null。
{
"keyToNull": null, # This may be null, or a String
"keyToString": "some value"
}
下面的方法对我有用,但我想知道是否有一种方法可以将每组两种期望合并成一行,因为我有很多属性需要检查:
import static org.springframework.test.web.servlet.result.MockMvcResu
我试图使用com.jayway.jsonpath.JsonPath从JSON字符串读取键/值:
String contentAsString = mvcResult.getResponse().getContentAsString();
System.out.println(contentAsString);
Object value = JsonPath.read(contentAsString, "$.key");
但我知道错误是:
Expected to find an object with property ['key'] in path $ but
我的简单生锈程序使用jsonpath机箱来查找json文档中的一些值。
我使用的代码如下
use serde::Deserialize;
extern crate jsonpath;
extern crate serde_json;
use jsonpath::Selector;
use serde_json::Value;
use std::any::{Any, TypeId};
fn main() {
let jsondoc = r#"
{
"a": 10,
"b": "a
如何从json响应下面使用response路径获得密钥organization.email的值?
{
"organization.email": [
"The organization.email has already been taken."
]
}
这是使用的放心测试代码。
package com.api.tests;
import org.testng.annotations.Test;
import io.restassured.path.json.JsonPath;
public class JsonTest {