本文整理汇总了Java中com.jayway.jsonpath.JsonPath.read方法的典型用法代码示例。如果您正苦于以下问题:Java JsonPath.read方法的具体用法?Java JsonPath.read怎么用?Java JsonPath.read使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.jayway.jsonpath.JsonPath
的用法示例。
在下文中一共展示了JsonPath.read方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getAnswer
import com.jayway.jsonpath.JsonPath; //导入方法依赖的package包/类
public static String getAnswer(RestTemplate restTemplate, String question) {
String url = "http://www.tuling123.com/openapi/api";
HttpHeaders headers = new HttpHeaders();
headers.add("Ocp-Apim-Subscription-Key", "3f5a37d9698744f3b40c89e2f0c94fb1");
headers.add("Content-Type", "application/x-www-form-urlencoded");
MultiValueMap<String, String> bodyMap = new LinkedMultiValueMap<>();
bodyMap.add("key", "e2e33efb4efb4e5794b48a18578384ee");
bodyMap.add("info", question);
HttpEntity<MultiValueMap<String, String>> requestEntity = new HttpEntity<>(bodyMap, headers);
String result = restTemplate.postForObject(url, requestEntity, String.class);
return JsonPath.read(result, "$.text");
}
示例2: updateServiceData
import com.jayway.jsonpath.JsonPath; //导入方法依赖的package包/类
public void updateServiceData() {
serviceConfigMap.clear();
String serviceData = marathonGateway.getMarathonServiceDetails();
Map<String, String> myMap = new HashMap<String, String>();
ObjectMapper objectMapper = new ObjectMapper();
try {
myMap = objectMapper.readValue(serviceData.getBytes(), HashMap.class);
List<Map<String, Object>> services = JsonPath.read(myMap, "$['apps'][?]", filter);
for (Map service : services) {
String serviceId = (String) service.get("id");
LOG.debug("parsing service metadata: " + serviceId);
serviceConfigMap.put(serviceId, new ServiceConfig(service));
}
} catch (IOException e) {
LOG.error("error in updateServiceData :", e);
}
}
示例3: getField
import com.jayway.jsonpath.JsonPath; //导入方法依赖的package包/类
private String getField(Object document, String fieldJsonPath)
{
String result = null;
try
{
result = JsonPath.read(document, fieldJsonPath);
} catch (Exception e)
{
e.printStackTrace();
}
return result;
}
示例4: readField
import com.jayway.jsonpath.JsonPath; //导入方法依赖的package包/类
public static String readField(String body, String jpath) {
try {
return JsonPath.read(body, jpath);
} catch (Exception e) {
log.debug("Error reading Xm path {}", jpath);
return null;
}
}
示例5: getEntityField
import com.jayway.jsonpath.JsonPath; //导入方法依赖的package包/类
private static Object getEntityField(String entity, String field) {
try {
return JsonPath.read(entity, "$." + field);
} catch (Exception ex) {
log.trace("JsonPath exception", ex);
try {
return JsonPath.read(entity, "$.xmEntity." + field);
} catch (Exception e) {
log.trace("JsonPath exception", e);
return "";
}
}
}
示例6: EnsureSimplePatternCompiles
import com.jayway.jsonpath.JsonPath; //导入方法依赖的package包/类
@Test
public void EnsureSimplePatternCompiles() throws Exception {
final JsonPath pattern = JsonPath.compile("$.test");
final Boolean read = pattern.<Boolean>read("{\"test\":true}");
then(read).isTrue();
// Investigate classpath problems (CNFE) in runtime
LoggerFactory.getLogger(JsonPathTest.class);
then(Class.forName("com.jayway.jsonpath.internal.path.CompiledPath")).isNotNull();
}
示例7: getNumberOfTweets
import com.jayway.jsonpath.JsonPath; //导入方法依赖的package包/类
public int getNumberOfTweets() throws IOException {
Map<String, String> params = new HashMap<>();
params.put("q", "*:*");
params.put("size", "0");
Response response = restClient.performRequest(
"GET",
"/twitter/tweet/_search",
params
);
Object jsonObject = jsonProvider.parse(EntityUtils.toString(response.getEntity()));
int hits = JsonPath.read(jsonObject, "$.hits.total");
return hits;
}
示例8: xmEntityFildsNoRelationFields
import com.jayway.jsonpath.JsonPath; //导入方法依赖的package包/类
@Test
@Transactional
public void xmEntityFildsNoRelationFields() throws Exception {
assertThat(xmEntityIncoming.getAttachments().size()).isGreaterThan(0);
assertThat(xmEntityIncoming.getTags().size()).isGreaterThan(0);
assertThat(xmEntityIncoming.getLocations().size()).isGreaterThan(0);
// Create the XmEntity with tag
MvcResult result = performPost("/api/xm-entities", xmEntityIncoming)
.andExpect(status().isCreated())
.andExpect(jsonPath("$.key").value(DEFAULT_KEY))
.andReturn();
int id = JsonPath.read(result.getResponse().getContentAsString(), "$.id");
List<XmEntity> xmEntityList = xmEntityRepository.findAll();
em.detach(xmEntityList.get(xmEntityList.size() - 1));
//);
performGet("/api/xm-entities/{id}?embed=id", id)
.andExpect(status().isOk())
.andDo(this::printMvcResult)
.andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE))
.andExpect(jsonPath("$.id").value(id))
.andExpect(jsonPath("$.key").value(DEFAULT_KEY))
.andExpect(jsonPath("$.typeKey").value(DEFAULT_TYPE_KEY))
.andExpect(jsonPath("$.stateKey").value(DEFAULT_STATE_KEY))
.andExpect(jsonPath("$.name").value(DEFAULT_NAME))
.andExpect(jsonPath("$.startDate").value(sameInstant(DEFAULT_START_DATE)))
.andExpect(jsonPath("$.updateDate").value(sameInstant(DEFAULT_UPDATE_DATE)))
.andExpect(jsonPath("$.endDate").value(sameInstant(DEFAULT_END_DATE)))
.andExpect(jsonPath("$.description").value(DEFAULT_DESCRIPTION))
.andExpect(jsonPath("$.data.AAAAAAAAAA").value("BBBBBBBBBB"))
.andExpect(jsonPath("$.attachments").value(nullValue()))
.andExpect(jsonPath("$.tags").value(nullValue()))
.andExpect(jsonPath("$.locations").value(nullValue()));
}
示例9: readField
import com.jayway.jsonpath.JsonPath; //导入方法依赖的package包/类
public static String readField(String json, String field) {
Object value = JsonPath.read(json, field, ALWAYS_TRUE_PREDICATE);
if (value == null) {
return null;
}
if (Map.class.isAssignableFrom(value.getClass())) {
return JsonPath.parse(value).jsonString();
} else {
return String.valueOf(value);
}
}
示例10: prepareCalendar
import com.jayway.jsonpath.JsonPath; //导入方法依赖的package包/类
private int prepareCalendar() throws Exception {
// Create the XmEntity with tag
MvcResult result = performPost("/api/xm-entities", xmEntityIncoming)
.andExpect(status().isCreated())
.andExpect(jsonPath("$.key").value(DEFAULT_KEY))
.andReturn();
int id = JsonPath.read(result.getResponse().getContentAsString(), "$.id");
xmEntityIncoming.setId((long) id);
val calendar = new Calendar().name("name").typeKey("TYPEKEY").startDate(Instant.now())
.xmEntity(xmEntityIncoming);
MvcResult resultSaveCalendar = performPost("/api/calendars", calendar)
.andExpect(status().is2xxSuccessful())
.andReturn();
int calendarId = JsonPath.read(resultSaveCalendar.getResponse().getContentAsString(), "$.id");
calendar.setId((long) calendarId);
val event = new Event().typeKey("TYPEKEY").title("title").startDate(Instant.now())
.calendar(calendar).assigned(xmEntityIncoming);
MvcResult resultSaveEvent = performPost("/api/events", event)
.andExpect(status().is2xxSuccessful())
.andReturn();
List<XmEntity> xmEntityList = xmEntityRepository.findAll();
em.detach(xmEntityList.get(xmEntityList.size() - 1));
List<Calendar> calendarList = calendarService.findAll();
em.detach(calendarList.get(calendarList.size() - 1));
return id;
}
示例11: getJsonPathAsString
import com.jayway.jsonpath.JsonPath; //导入方法依赖的package包/类
public static String getJsonPathAsString(String json, String path) {
Configuration conf = Configuration.defaultConfiguration().addOptions(Option.DEFAULT_PATH_LEAF_TO_NULL).addOptions(Option.SUPPRESS_EXCEPTIONS);
Object document = conf.jsonProvider().parse(json);
Object jsonObj = JsonPath.read(document, path);
return convertJsonPathValueToString(jsonObj);
}
示例12: getStatus
import com.jayway.jsonpath.JsonPath; //导入方法依赖的package包/类
private String getStatus(String json) {
return JsonPath.read(json, "$.status");
}
示例13: getErroredTransformations
import com.jayway.jsonpath.JsonPath; //导入方法依赖的package包/类
private List<Map<String, String>> getErroredTransformations(String json) {
return JsonPath.read(json, "$.errored_transformations");
}
示例14: getRunningTransformations
import com.jayway.jsonpath.JsonPath; //导入方法依赖的package包/类
private List<Map<String, String>> getRunningTransformations(String json) {
return JsonPath.read(json, "$.running_transformations");
}
示例15: getPlatforms
import com.jayway.jsonpath.JsonPath; //导入方法依赖的package包/类
private List<String> getPlatforms(String json) {
return JsonPath.read(json, "$.installed_plugins");
}