本文整理了Java中play.libs.Json.parse()
方法的一些代码示例,展示了Json.parse()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Json.parse()
方法的具体详情如下:
包路径:play.libs.Json
类名称:Json
方法名:parse
[英]Parses a InputStream representing a json, and return it as a JsonNode.
[中]解析表示json的InputStream,并将其作为JsonNode返回。
代码示例来源:origin: com.typesafe.play/play_2.11
@Override
protected JsonNode parse(Http.RequestHeader request, ByteString bytes) throws Exception {
return play.libs.Json.parse(bytes.iterator().asInputStream());
}
}
代码示例来源:origin: com.typesafe.play/play_2.12
@Override
protected JsonNode parse(Http.RequestHeader request, ByteString bytes) throws Exception {
return play.libs.Json.parse(bytes.iterator().asInputStream());
}
}
代码示例来源:origin: com.typesafe.play/play_2.11
/**
* Set a Json Body to this request.
* The <tt>Content-Type</tt> header of the request is set to <tt>application/json</tt>.
*
* @param json the JsValue
* @return the modified builder
*/
public RequestBuilder bodyJson(JsValue json) {
return bodyJson(Json.parse(play.api.libs.json.Json.stringify(json)));
}
代码示例来源:origin: com.typesafe.play/play
@Override
protected JsonNode parse(Http.RequestHeader request, ByteString bytes) throws Exception {
return play.libs.Json.parse(bytes.iterator().asInputStream());
}
}
代码示例来源:origin: com.typesafe.play/play_2.12
/**
* Set a Json Body to this request.
* The <tt>Content-Type</tt> header of the request is set to <tt>application/json</tt>.
*
* @param json the JsValue
* @return the modified builder
*/
public RequestBuilder bodyJson(JsValue json) {
return bodyJson(Json.parse(play.api.libs.json.Json.stringify(json)));
}
代码示例来源:origin: com.typesafe.play/play
/**
* Set a Json Body to this request.
* The <tt>Content-Type</tt> header of the request is set to <tt>application/json</tt>.
*
* @param json the JsValue
* @return the modified builder
*/
public RequestBuilder bodyJson(JsValue json) {
return bodyJson(Json.parse(play.api.libs.json.Json.stringify(json)));
}
代码示例来源:origin: com.typesafe.play/play-java-ws
/**
* Get the response body as a {@link JsonNode}
*
* @return the json response
*/
@Override
public JsonNode asJson() {
// Jackson will automatically detect the correct encoding according to the rules in RFC-4627
return Json.parse(ahcResponse.getResponseBodyAsStream());
}
代码示例来源:origin: ch.epfl.gsn/gsn-core
public DataField[] getRemoteStructure() throws IOException, ClassNotFoundException {
HttpGet get = new HttpGet(wsURL + "/api/sensors/" + vsName);
try {
String content = doRequest(get);
JsonNode jn = Json.parse(content).get("properties");
DataField[] df = new DataField[jn.get("fields").size()-1];
int i = 0;
for(JsonNode f : jn.get("fields")){
if (f.get("name").asText().equals("timestamp")) continue;
df[i] = new DataField(f.get("name").asText(),f.get("type").asText());
i++;
}
return df;
} catch (Exception e){
logger.error(e.getMessage(), e);
}
return null;
}
代码示例来源:origin: com.commercetools.sunrise/common
/**
* {@inheritDoc}
*/
@Override
public <U> Optional<U> findObjectByKey(final String key, final Class<U> clazz) {
return findValueByKey(key)
.flatMap(valueAsJson -> {
try {
final U value = Json.fromJson(Json.parse(valueAsJson), clazz);
return Optional.of(value);
} catch (RuntimeException e) {
logger.error("Could not parse value in session key \"{}\" into type \"{}\"", key, clazz.getSimpleName(), e);
return Optional.empty();
}
});
}
代码示例来源:origin: ch.epfl.gsn/gsn-core
public String getToken(){
HttpPost post = new HttpPost(wsURL + "/oauth2/token");
List<BasicNameValuePair> parametersBody = new ArrayList<BasicNameValuePair>();
parametersBody.add(new BasicNameValuePair("grant_type", "client_credentials"));
parametersBody.add(new BasicNameValuePair("client_id", clientId));
parametersBody.add(new BasicNameValuePair("client_secret", clientSecret));
HttpResponse response = null;
try {
post.setEntity(new UrlEncodedFormEntity(parametersBody, StandardCharsets.UTF_8));
response = client.execute(post);
int code = response.getStatusLine().getStatusCode();
if (code == 401) {
// Add Basic Authorization header
post.addHeader("Authorization",Base64.encodeBase64String((clientId+":"+clientSecret).getBytes()));
post.releaseConnection();
response = client.execute(post);
code = response.getStatusLine().getStatusCode();
}
if (code == 200){
String content = EntityUtils.toString(response.getEntity());
return Json.parse(content).get("access_token").asText();
}
} catch (Exception e){
logger.error(e.getMessage(), e);
}
return null;
}
代码示例来源:origin: ch.epfl.gsn/gsn-core
JsonNode jn = Json.parse(s).get("properties");
DataField[] df = new DataField[jn.get("fields").size()-1];
int i = 0;
内容来源于网络,如有侵权,请联系作者删除!