當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。