本文整理匯總了Java中org.codehaus.jettison.json.JSONArray.put方法的典型用法代碼示例。如果您正苦於以下問題:Java JSONArray.put方法的具體用法?Java JSONArray.put怎麽用?Java JSONArray.put使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.codehaus.jettison.json.JSONArray
的用法示例。
在下文中一共展示了JSONArray.put方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getAnnotatedSnippetS3
import org.codehaus.jettison.json.JSONArray; //導入方法依賴的package包/類
private JSONArray getAnnotatedSnippetS3(String query, WikipediaInterface wikiApi) throws JSONException, IOException {
JSONArray res = new JSONArray();
if (this.annotatedSnippetsAndBoldsS3.containsKey(query))
for (Triple<String, HashSet<Annotation>, HashSet<Mention>> p : this.annotatedSnippetsAndBoldsS3.get(query)) {
JSONObject pairJs = new JSONObject();
res.put(pairJs);
pairJs.put("snippet", p.getLeft());
JSONArray annotationsJs = new JSONArray();
pairJs.put("parts", annotationsJs);
int lastIdx = 0;
for (Annotation a : SmaphUtils.sorted(p.getMiddle())) {
annotationsJs.put(getTextPartJson(p.getLeft(), lastIdx, a.getPosition(), p.getRight()));
JSONObject annotationJs = getTextPartJson(p.getLeft(), a.getPosition(), a.getPosition() + a.getLength(),
p.getRight());
annotationsJs.put(annotationJs);
annotationJs.put("title", wikiApi.getTitlebyId(a.getConcept()));
annotationJs.put("wid", a.getConcept());
annotationJs.put("url", widToUrl(a.getConcept(), wikiApi));
lastIdx = a.getPosition() + a.getLength();
}
annotationsJs.put(getTextPartJson(p.getLeft(), lastIdx, p.getLeft().length(), p.getRight()));
}
return res;
}
示例2: getEntityFeaturesJson
import org.codehaus.jettison.json.JSONArray; //導入方法依賴的package包/類
private JSONArray getEntityFeaturesJson(
HashMap<String, List<Triple<Integer, HashMap<String, Double>, Boolean>>> source,
String query, WikipediaInterface wikiApi) throws JSONException,
IOException {
JSONArray res = new JSONArray();
if (source.containsKey(query))
for (Triple<Integer, HashMap<String, Double>, Boolean> p : source
.get(query)) {
JSONObject pairJs = new JSONObject();
res.put(pairJs);
pairJs.put("wid", p.getLeft());
pairJs.put("title", wikiApi.getTitlebyId(p.getLeft()));
pairJs.put("url", widToUrl(p.getLeft(), wikiApi));
JSONObject features = new JSONObject();
pairJs.put("features", features);
for (String ftrName : SmaphUtils.sorted(p.getMiddle().keySet()))
features.put(ftrName, p.getMiddle().get(ftrName));
pairJs.put("accepted", p.getRight());
}
return res;
}
示例3: getSourceSearchResultJson
import org.codehaus.jettison.json.JSONArray; //導入方法依賴的package包/類
private JSONArray getSourceSearchResultJson(
HashMap<String, List<Triple<Integer, String, Integer>>> source,
String query, WikipediaInterface wikiApi) throws JSONException, IOException {
JSONArray res = new JSONArray();
if (source.containsKey(query))
for (Triple<Integer, String, Integer> t : source.get(query)) {
JSONObject triple = new JSONObject();
res.put(triple);
triple.put("rank", t.getLeft());
triple.put("wid", t.getRight());
triple.put("title",
t.getRight() >= 0 ? wikiApi.getTitlebyId(t.getRight())
: "---not a wikipedia page---");
triple.put("url", t.getMiddle());
}
return res;
}
示例4: getResultsJson
import org.codehaus.jettison.json.JSONArray; //導入方法依賴的package包/類
private JSONArray getResultsJson(String query, WikipediaInterface wikiApi)
throws JSONException, IOException {
JSONArray res = new JSONArray();
if (result.containsKey(query))
for (ScoredAnnotation a: result.get(query)) {
JSONObject triple = new JSONObject();
res.put(triple);
triple.put("begin", a.getPosition());
triple.put("end", a.getPosition() + a.getLength());
triple.put("score", a.getScore());
triple.put("wid", a.getConcept());
triple.put("title", wikiApi.getTitlebyId(a.getConcept()));
triple.put("url", widToUrl(a.getConcept(), wikiApi));
}
return res;
}
示例5: listFiles
import org.codehaus.jettison.json.JSONArray; //導入方法依賴的package包/類
public void listFiles(JSONObject response) throws JSONException, IOException {
File canonicalDir = destDir.getCanonicalFile();
int uriDirectoryLength = canonicalDir.toURI().toString().length();
JSONArray jArray = new JSONArray();
for (File f : FileUtils.listFiles(canonicalDir, TrueFileFilter.INSTANCE, TrueFileFilter.INSTANCE)) {
File canonnicalF = f.getCanonicalFile();
JSONObject jObj = new JSONObject();
jObj.put("uri", URLDecoder.decode(canonnicalF.toURI().toString().substring(uriDirectoryLength), "UTF-8"));
jObj.put("date", canonnicalF.lastModified());
jObj.put("size", canonnicalF.length());
jArray.put(jObj);
}
response.put("files", jArray);
response.put("date", destDir.lastModified());
}
示例6: getTextPartJson
import org.codehaus.jettison.json.JSONArray; //導入方法依賴的package包/類
private JSONObject getTextPartJson(String text, int begin, int end, Collection<Mention> bolds) throws JSONException{
JSONObject textJs = new JSONObject();
textJs.put("text", text.substring(begin, end));
JSONArray boldsJs = new JSONArray();
textJs.put("bolds", boldsJs);
for (Mention bold : bolds.stream().filter(b -> new Mention(begin, end-begin).overlaps(b)).collect(Collectors.toList())){
boldsJs.put(new JSONObject()
.put("begin",
Math.max(bold.getPosition() - begin, 0))
.put("end",
Math.min(bold.getPosition() + bold.getLength() - begin, end-begin)));
};
return textJs;
}
示例7: encodeResponseJson
import org.codehaus.jettison.json.JSONArray; //導入方法依賴的package包/類
private String encodeResponseJson(HashSet<ScoredAnnotation> annotations, SmaphAnnotator annotator) {
WikipediaInterface wikiApi = (WikipediaInterface) context.getAttribute("wikipedia-api");
JSONObject res = new JSONObject();
try {
res.put("response-code", "OK");
res.put("annotator", annotator.getName());
JSONArray annotJson = new JSONArray();
for (ScoredAnnotation ann : annotations) {
int wid = ann.getConcept();
String title = wikiApi.getTitlebyId(ann.getConcept());
if (wid >= 0 && title != null) {
JSONObject annJson = new JSONObject();
annJson.put("begin", ann.getPosition());
annJson.put("end", ann.getPosition() + ann.getLength());
annJson.put("wid", wid);
annJson.put("title", title);
annJson.put("url", SmaphUtils.getWikipediaURI(title));
annJson.put("score", ann.getScore());
annotJson.put(annJson);
}
}
res.put("annotations", annotJson);
} catch (JSONException | IOException e) {
throw new RuntimeException(e);
}
return res.toString();
}
示例8: addCandidate
import org.codehaus.jettison.json.JSONArray; //導入方法依賴的package包/類
private void addCandidate(Context js_context, JSONArray result) {
if (candidate != null) {
if (js_filter != null) {
try {
Scriptable scope = js_context.initStandardObjects(null, true);
scope.put("category", scope, candidate.getString(0));
scope.put("time", scope, candidate.getString(1));
scope.put("level", scope, candidate.getString(2));
scope.put("thread", scope, candidate.getString(3));
scope.put("message", scope, candidate.getString(4));
StringBuffer extra = new StringBuffer();
for (int i = 5; i < candidate.length(); i++) {
String sub_extra = candidate.getString(i);
extra.append(sub_extra).append(' ');
delim_extra.reset(sub_extra);
if (delim_extra.matches() && delim_extra.groupCount() == 2) {
scope.put(delim_extra.group(1), scope, delim_extra.group(2));
}
}
if (extra.length() > 0) {
scope.put("extra", scope, extra.substring(0, extra.length() - 1));
}
scope.setParentScope(js_utils);
if (Context.toBoolean(js_filter.exec(js_context, scope))) {
result.put(candidate);
}
} catch (Exception e) {
// TODO: handle exception
}
} else {
result.put(candidate);
}
candidate = null;
}
}
示例9: setUser
import org.codehaus.jettison.json.JSONArray; //導入方法依賴的package包/類
public void setUser(String username, String password, Set<Role> roles) throws EngineException {
try {
if (StringUtils.isBlank(username)) {
throw new IllegalArgumentException("Blank username not allowed");
}
if (StringUtils.isBlank(password)) {
throw new IllegalArgumentException("Blank password not allowed");
}
if ("admin".equals(username)) {
throw new IllegalArgumentException("Cannot defined another 'admin' user");
}
JSONArray array = new JSONArray();
for (Role role : roles) {
array.put(role.name());
}
JSONObject user = new JSONObject();
user.put("password", password);
user.put("roles", array);
synchronized (this) {
JSONObject db = load();
db.put(username, user);
save(db);
}
} catch (Exception e) {
throw new EngineException("Failed to set the role", e);
}
}
示例10: getDeletedDocs
import org.codehaus.jettison.json.JSONArray; //導入方法依賴的package包/類
protected JSONArray getDeletedDocs(JSONArray rows) throws JSONException {
if (isEnabled()) {
if (rows.length() > 0) {
JSONArray deletedDocs = new JSONArray();
for (int i = 0; i < rows.length(); i++) {
JSONObject doc = CouchKey.doc.JSONObject(rows.getJSONObject(i));
deletedDocs.put(doc);
}
return deletedDocs;
}
}
return null;
}
示例11: getChunk
import org.codehaus.jettison.json.JSONArray; //導入方法依賴的package包/類
protected JSONArray getChunk(JSONArray array, int offset) throws JSONException {
if (offset == 0 && array.length() < chunk) {
return array;
}
int limit = Math.min(array.length(), offset + chunk);
JSONArray sub = new JSONArray();
for (int i = offset; i < limit; i++) {
sub.put(array.get(i));
}
return sub;
}
示例12: runDocs
import org.codehaus.jettison.json.JSONArray; //導入方法依賴的package包/類
protected void runDocs(InternalHttpServletRequest request, JSONArray rows) throws JSONException, EngineException {
if (isEnabled()) {
if (rows != null && rows.length() > 0) {
// Retrieve the first results
JSONArray docs = new JSONArray();
for (int i = 0; i < rows.length(); i++) {
docs.put(CouchKey.doc.JSONObject(rows.getJSONObject(i)));
}
executeSequence(request, docs);
}
}
}
示例13: listOntologies
import org.codehaus.jettison.json.JSONArray; //導入方法依賴的package包/類
@GET
@Consumes(MediaType.WILDCARD)
@Produces(MediaType.APPLICATION_JSON)
public Response listOntologies(){
JSONArray array = new JSONArray();
OntologyInfo[] ontologyInfos = ontonetHub.getOntologiesInfo();
for(OntologyInfo ontologyInfo : ontologyInfos){
try {
String jsonString = objectMapper.writeValueAsString(ontologyInfo);
JSONObject json = new JSONObject(jsonString);
String ontologyId = json.getString("ontologyID");
if(ontologyId != null){
String ontologySourceURI = uriInfo.getBaseUri() + "ontonethub/ontology/" + ontologyId + "/source";
json.put("ontologySource", ontologySourceURI);
}
array.put(json);
} catch (JsonProcessingException | JSONException e) {
log.error(e.getMessage(), e);
}
}
return Response.ok(array.toString()).build();
}
示例14: createResponse
import org.codehaus.jettison.json.JSONArray; //導入方法依賴的package包/類
public static Response createResponse( Response.Status status, List<JsonSerializable> json ) throws JSONException {
JSONArray jsonArray = new JSONArray();
for( int i = 0; i < json.size(); i++ ) {
jsonArray.put( json.get(i).toJson() );
}
return Response.status( status ).entity( jsonArray.toString() ).build();
}
示例15: main
import org.codehaus.jettison.json.JSONArray; //導入方法依賴的package包/類
public static void main(String[] args) throws IOException, JSONException {
JSONArray jsonArray = new JSONArray();
BufferedReader br = new BufferedReader(new FileReader(args[0]));
String line = br.readLine();
FileWriter fileWriter = new FileWriter(args[1]);
BufferedWriter bufferedWriter = new BufferedWriter(fileWriter);
while (line != null) {
JSONObject article = new JSONObject();
String[] title_emotion_count = line.split("\t");
JSONObject emotionList = new JSONObject();
emotionList.put(title_emotion_count[1], title_emotion_count[2]);
article.put("title", title_emotion_count[0]);
for (int i = 0; i < 2; i++) {
line = br.readLine();
title_emotion_count = line.split("\t");
emotionList.put(title_emotion_count[1], title_emotion_count[2]);
}
article.put("data", emotionList);
jsonArray.put(article);
line = br.readLine();
}
bufferedWriter.write(jsonArray.toString());
br.close();
bufferedWriter.close();
}