本文整理了Java中javax.json.Json.createReader()
方法的一些代码示例,展示了Json.createReader()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Json.createReader()
方法的具体详情如下:
包路径:javax.json.Json
类名称:Json
方法名:createReader
[英]Creates a JSON reader from a byte stream. The character encoding of the stream is determined as described in RFC 7159.
[中]从字节流创建JSON读取器。流的字符编码如RFC 7159中所述确定。
代码示例来源:origin: wildfly/wildfly
public static JsonObject readJsonObject(String jsonString) {
return Json.createReader(new StringReader(jsonString)).readObject();
}
代码示例来源:origin: wildfly/wildfly
private static JsonObject getJsonResponse(HttpURLConnection connection) throws AcmeException {
JsonObject jsonResponse;
try (InputStream inputStream = new BufferedInputStream(connection.getResponseCode() < 400 ? connection.getInputStream() : connection.getErrorStream())) {
jsonResponse = Json.createReader(inputStream).readObject();
} catch (IOException e) {
throw acme.unableToObtainJsonResponseFromAcmeServer(e);
}
return jsonResponse;
}
代码示例来源:origin: wildfly/wildfly
public static JsonArray readJsonArray(String jsonString) {
return Json.createReader(new StringReader(jsonString)).readArray();
}
代码示例来源:origin: stanfordnlp/CoreNLP
public static Map<String, Set<CandidatePhrase>> readSeedWordsFromJSONString(String str){
Map<String, Set<CandidatePhrase>> seedWords = new HashMap<>();
JsonReader jsonReader = Json.createReader(new StringReader(str));
JsonObject obj = jsonReader.readObject();
jsonReader.close();
for (String o : obj.keySet()){
seedWords.put(o, new HashSet<>());
JsonArray arr = obj.getJsonArray(o);
for(JsonValue v: arr)
seedWords.get(o).add(CandidatePhrase.createOrGet(v.toString()));
}
return seedWords;
}
代码示例来源:origin: wildfly/wildfly
JsonReader reader = Json.createReader(
new StringReader(builder.toString()));
JsonValue value = reader.readValue();
reader.close();
代码示例来源:origin: wildfly/wildfly
private JsonObject extractClaims(String encodedClaims) throws RealmUnavailableException {
try {
Base64.Decoder urlDecoder = Base64.getUrlDecoder();
CodePointIterator decodedClaims = CodePointIterator.ofUtf8Bytes(urlDecoder.decode(encodedClaims));
return Json.createReader(decodedClaims.asUtf8().asInputStream()).readObject();
} catch (Exception cause) {
throw log.tokenRealmJwtParseFailed(cause);
}
}
代码示例来源:origin: stanfordnlp/CoreNLP
public String doNewPhrases(String line) throws Exception {
System.out.println("adding new phrases");
ConstantsAndVariables constVars = new ConstantsAndVariables(props, humanLabelClasses.keySet(), humanLabelClasses);
JsonReader jsonReader = Json.createReader(new StringReader(line));
JsonObject objarr = jsonReader.readObject();
for(Map.Entry<String, JsonValue> o: objarr.entrySet()){
String label = o.getKey();
Set<CandidatePhrase> seed = new HashSet<>();
JsonArray arr = objarr.getJsonArray(o.getKey());
for(int i = 0; i < arr.size(); i++){
String seedw = arr.getString(i);
System.out.println("adding " + seedw + " to seed ");
seed.add(CandidatePhrase.createOrGet(seedw));
}
seedWords.get(label).addAll(seed);
constVars.addSeedWords(label, seed);
GetPatternsFromDataMultiClass.runLabelSeedWords(Data.sents, humanLabelClasses.get(label), label, seed, constVars, false);
//model.labelWords(label, labelclass, Data.sents, seed);
}
return "SUCCESS added new phrases";
}
代码示例来源:origin: traccar/traccar
@Override
protected Object decode(
Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
FullHttpRequest request = (FullHttpRequest) msg;
JsonArray result = Json.createReader(new StringReader(request.content().toString(StandardCharsets.UTF_8)))
.readArray();
List<Position> positions = new LinkedList<>();
for (int i = 0; i < result.size(); i++) {
JsonObject message = result.getJsonObject(i);
JsonString ident = message.getJsonString("ident");
if (ident == null) {
continue;
}
DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, ident.getString());
if (deviceSession == null) {
continue;
}
Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
decodePosition(message, position);
positions.add(position);
}
sendResponse(channel, HttpResponseStatus.OK);
return positions;
}
代码示例来源:origin: wildfly/wildfly
JsonObject jsonObject = Json.createReader(inputStream).readObject();
String accessToken = jsonObject.getString("access_token");
return credentialType.cast(new BearerTokenCredential(accessToken));
代码示例来源:origin: stanfordnlp/CoreNLP
private int changeAnnotation(String line, boolean remove){
int tokensNum = 0;
JsonReader jsonReader = Json.createReader(new StringReader(line));
JsonObject objarr = jsonReader.readObject();
for(String label: objarr.keySet()) {
JsonObject obj4label = objarr.getJsonObject(label);
for(String sentid: obj4label.keySet()){
JsonArray tokenArry = obj4label.getJsonArray(sentid);
for(JsonValue tokenid: tokenArry){
tokensNum ++;
Data.sents.get(sentid).getTokens().get(Integer.parseInt(tokenid.toString())).set(humanLabelClasses.get(label), remove ? backgroundSymbol: label);
}
}
}
return tokensNum;
}
代码示例来源:origin: stanfordnlp/CoreNLP
JsonReader json = Json.createReader(new StringReader(jsonString));
SemanticGraph tree = new SemanticGraph();
JsonArray array = json.readArray();
代码示例来源:origin: jeremylong/DependencyCheck
case 200:
try (InputStream in = new BufferedInputStream(conn.getInputStream());
JsonReader jsonReader = Json.createReader(in)) {
final JSONObject jsonResponse = new JSONObject(jsonReader.readObject().toString());
final NpmAuditParser parser = new NpmAuditParser();
return parser.parse(jsonResponse);
代码示例来源:origin: stanfordnlp/CoreNLP
void setUpProperties(String line, boolean readFile, boolean writeOutputToFile, String additionalSeedWordsFiles) throws IOException, ClassNotFoundException {
JsonReader jsonReader = Json.createReader(new StringReader(line));
JsonObject objarr = jsonReader.readObject();
jsonReader.close();
Properties props = new Properties();
代码示例来源:origin: org.glassfish/javax.json
JsonReader reader = Json.createReader(
new StringReader(builder.toString()));
JsonValue value = reader.readValue();
reader.close();
代码示例来源:origin: wildfly/wildfly
private Signature createSignature(String encodedHeader, String encodedClaims) throws NoSuchAlgorithmException, SignatureException, RealmUnavailableException {
byte[] headerDecoded = Base64.getUrlDecoder().decode(encodedHeader);
JsonObject headers = Json.createReader(ByteIterator.ofBytes(headerDecoded).asInputStream()).readObject();
String headerAlg = resolveAlgorithm(headers);
Signature signature = Signature.getInstance(headerAlg);
try {
PublicKey publicKey = resolvePublicKey(headers);
if (publicKey == null) {
log.debug("Public key could not be resolved.");
return null;
}
signature.initVerify(publicKey);
} catch (InvalidKeyException e) {
e.printStackTrace();
return null;
}
signature.update((encodedHeader + "." + encodedClaims).getBytes());
return signature;
}
代码示例来源:origin: apache/nifi
for (PropertyDescriptor attachment : attachments) {
String s = context.getProperty(attachment).evaluateAttributeExpressions(flowFile).getValue();
JsonReader reader = Json.createReader(new StringReader(s));
JsonObject attachmentJson = reader.readObject();
jsonArrayBuiler.add(attachmentJson);
代码示例来源:origin: hyperledger/fabric-sdk-java
JsonReader reader = Json.createReader(new StringReader(responseBody));
JsonObject jobj = (JsonObject) reader.read();
代码示例来源:origin: jeremylong/DependencyCheck
try (JsonReader jsonReader = Json.createReader(FileUtils.openInputStream(dependencyFile))) {
final JsonObject json = jsonReader.readObject();
final String parentName = json.getString("name", "");
final String parentVersion = json.getString("version", "");
代码示例来源:origin: traccar/traccar
JsonObject json = Json.createReader(new StringReader(URLDecoder.decode(
request.content().toString(StandardCharsets.UTF_8).split("=")[0], "UTF-8"))).readObject();
代码示例来源:origin: hyperledger/fabric-sdk-java
JsonReader reader = Json.createReader(new StringReader(responseBody));
JsonObject jsonst = (JsonObject) reader.read();
内容来源于网络,如有侵权,请联系作者删除!