当前位置: 首页>>代码示例>>Java>>正文


Java JsonPath.read方法代码示例

本文整理汇总了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");
}
 
开发者ID:xjtushilei,项目名称:knowledge-forest-dialogue-recommendation,代码行数:17,代码来源:Tuling123.java

示例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);
    }
}
 
开发者ID:dcos-utilities,项目名称:f5-marathon-autoscale,代码行数:20,代码来源:MarathonSDService.java

示例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;
}
 
开发者ID:basavaraj1985,项目名称:DolphinNG,代码行数:13,代码来源:JIRAClient.java

示例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;
    }
}
 
开发者ID:xm-online,项目名称:xm-uaa,代码行数:9,代码来源:JsonUtils.java

示例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 "";
        }
    }
}
 
开发者ID:xm-online,项目名称:xm-commons,代码行数:14,代码来源:TimelineEventProducer.java

示例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();
}
 
开发者ID:JetBrains,项目名称:teamcity-hashicorp-vault-plugin,代码行数:11,代码来源:JsonPathTest.java

示例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;
}
 
开发者ID:pkiraly,项目名称:metadata-qa-marc,代码行数:14,代码来源:MarcElasticsearchClient.java

示例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()));

}
 
开发者ID:xm-online,项目名称:xm-ms-entity,代码行数:40,代码来源:XmEntityResourceExtendedIntTest.java

示例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);
    }
}
 
开发者ID:Atypon-OpenSource,项目名称:wayf-cloud,代码行数:14,代码来源:HttpTestUtil.java

示例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;
}
 
开发者ID:xm-online,项目名称:xm-ms-entity,代码行数:37,代码来源:XmEntityResourceExtendedIntTest.java

示例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);
}
 
开发者ID:uber,项目名称:uberscriptquery,代码行数:7,代码来源:JsonPathUtils.java

示例12: getStatus

import com.jayway.jsonpath.JsonPath; //导入方法依赖的package包/类
private String getStatus(String json) {
    return JsonPath.read(json, "$.status");
}
 
开发者ID:StuPro-TOSCAna,项目名称:TOSCAna,代码行数:4,代码来源:TransformerHealthIndicatorTest.java

示例13: getErroredTransformations

import com.jayway.jsonpath.JsonPath; //导入方法依赖的package包/类
private List<Map<String, String>> getErroredTransformations(String json) {
    return JsonPath.read(json, "$.errored_transformations");
}
 
开发者ID:StuPro-TOSCAna,项目名称:TOSCAna,代码行数:4,代码来源:TransformerHealthIndicatorTest.java

示例14: getRunningTransformations

import com.jayway.jsonpath.JsonPath; //导入方法依赖的package包/类
private List<Map<String, String>> getRunningTransformations(String json) {
    return JsonPath.read(json, "$.running_transformations");
}
 
开发者ID:StuPro-TOSCAna,项目名称:TOSCAna,代码行数:4,代码来源:TransformerHealthIndicatorTest.java

示例15: getPlatforms

import com.jayway.jsonpath.JsonPath; //导入方法依赖的package包/类
private List<String> getPlatforms(String json) {
    return JsonPath.read(json, "$.installed_plugins");
}
 
开发者ID:StuPro-TOSCAna,项目名称:TOSCAna,代码行数:4,代码来源:TransformerHealthIndicatorTest.java


注:本文中的com.jayway.jsonpath.JsonPath.read方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。