本文整理汇总了Java中org.codehaus.jettison.json.JSONObject.put方法的典型用法代码示例。如果您正苦于以下问题:Java JSONObject.put方法的具体用法?Java JSONObject.put怎么用?Java JSONObject.put使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.codehaus.jettison.json.JSONObject
的用法示例。
在下文中一共展示了JSONObject.put方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: process
import org.codehaus.jettison.json.JSONObject; //导入方法依赖的package包/类
@Override
public void process(String key, ResultMessage resultMessage) {
try {
JSONObject payload = new JSONObject();
payload.put("id", resultMessage.getId());
payload.put("result_value", resultMessage.getResultValue());
payload.put("processing_time", resultMessage.getProcessingTime());
this.context().forward(key, payload.toString());
this.context().commit();
} catch (JSONException exception) {
exception.printStackTrace();
System.exit(1);
}
}
示例2: getAnnotatedSnippetS3
import org.codehaus.jettison.json.JSONObject; //导入方法依赖的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;
}
示例3: getEntityFeaturesJson
import org.codehaus.jettison.json.JSONObject; //导入方法依赖的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;
}
示例4: getSourceSearchResultJson
import org.codehaus.jettison.json.JSONObject; //导入方法依赖的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;
}
示例5: getResultsJson
import org.codehaus.jettison.json.JSONObject; //导入方法依赖的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;
}
示例6: doComputeContents
import org.codehaus.jettison.json.JSONObject; //导入方法依赖的package包/类
protected synchronized void doComputeContents() {
try {
pageImports.clear();
pageFunctions.clear();
JSONObject newComputedContent = initJsonComputed();
JSONObject jsonScripts = newComputedContent.getJSONObject("scripts");
computeScripts(jsonScripts);
newComputedContent.put("style", computeStyle());
newComputedContent.put("template", computeTemplate());
computedContents = newComputedContent;
} catch (JSONException e) {
e.printStackTrace();
}
}
示例7: getOntologySource
import org.codehaus.jettison.json.JSONObject; //导入方法依赖的package包/类
@GET
@Consumes(MediaType.WILDCARD)
@Produces({
KRFormat.RDF_XML,
KRFormat.RDF_JSON,
KRFormat.TURTLE,
KRFormat.N_TRIPLE,
KRFormat.N3,
"application/json-ld"
})
@Path("/{id}/source")
public Response getOntologySource(@PathParam("id") String id){
ResponseBuilder responseBuilder = null;
Model model;
try {
model = ontonetHub.getOntologySource(id);
responseBuilder = Response.ok(model);
} catch (NoSuchOntologyException e1) {
JSONObject json = new JSONObject();
try {
json.put("error", "No ontology exists with the ID provided.");
} catch (JSONException e) {
log.error(e.getMessage(), e);
}
responseBuilder = Response.status(Status.NOT_FOUND).entity(json);
}
return responseBuilder.build();
}
示例8: createResponse
import org.codehaus.jettison.json.JSONObject; //导入方法依赖的package包/类
public static Response createResponse( Response.Status status, Map<String,Object> map ) {
JSONObject jsonObject = new JSONObject();
try {
for( Map.Entry<String,Object> entry : map.entrySet() ) {
jsonObject.put( entry.getKey(), entry.getValue() );
}
}
catch( JSONException e ) {
return Response.status( Response.Status.INTERNAL_SERVER_ERROR ).entity( Response.Status.INTERNAL_SERVER_ERROR ).build();
}
return Response.status( status ).entity( jsonObject.toString() ).build();
}
示例9: callSetSearch
import org.codehaus.jettison.json.JSONObject; //导入方法依赖的package包/类
public CallSetSearch callSetSearch(String path)
throws JSONException, InterruptedException, IOException, ExternalDbUnavailableException {
final JSONObject jsonObject = new JSONObject();
jsonObject.put(Constants.PAGE_SIZE, Constants.VARIANTS_PAGE_SIZE);
jsonObject.put(Constants.VARIANT_SET_ID, path);
final String location = Constants.URL_GOOGLE_GENOMIC_API +
Constants.URL_CALL_SETS +
Constants.URL_SEARCH +
Constants.GOOGLE_API_KEY;
String geneData = httpDataManager.fetchData(location, jsonObject);
return objectMapper.readValue(geneData, CallSetSearch.class);
}
示例10: toXml
import org.codehaus.jettison.json.JSONObject; //导入方法依赖的package包/类
@Override
public Element toXml(org.w3c.dom.Document document) {
Element element = document.createElement("function");
element.setAttribute("classname", getClass().getName());
JSONObject jsondata = new JSONObject();
try {
jsondata.put("name", getObject().getName());
jsondata.put("value", getObject().getStringObject());
} catch (JSONException e) {}
CDATASection cDATASection = document.createCDATASection(jsondata.toString());
element.appendChild(cDATASection);
return element;
}
示例11: main
import org.codehaus.jettison.json.JSONObject; //导入方法依赖的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();
}
示例12: compose
import org.codehaus.jettison.json.JSONObject; //导入方法依赖的package包/类
@Override
public String compose(final String transferId, final InternalData data,
final MessageProtocol messageProtocol, final Map<DataType, DataTypeComposer> composer,
final Map<String, String> configuration) {
try {
typeKey = configuration.get(GlobalKey.TYPE);
transferIdKey = configuration.get(GlobalKey.TRANSFER_ID);
final JSONObject json = new JSONObject();
json.put(transferIdKey, transferId);
json.put(typeKey, messageProtocol.getExternalName());
final String currentMessage = messageProtocol.getInternalName();
final InternalObject internalObject = data.getObjects().get(currentMessage);
for (final MessageProtocolField protocolField : messageProtocol.getFields()) {
if (protocolField.isMandatory() && ((internalObject == null)
|| (internalObject.getFields().get(protocolField.getInternalName()) == null))) {
throw new IllegalArgumentException("Could not find protocol field for internal name ["
+ protocolField.getInternalName() + "]");
}
String value = StringUtils.EMPTY;
if (internalObject != null) {
value = internalObject.getFields().get(protocolField.getInternalName()) != null
? internalObject.getFields().get(protocolField.getInternalName()).getValue()
: protocolField.getDefaultValue();
}
value = ComposerUtils.compose(value, protocolField.getDataType());
json.put(protocolField.getExternalName(), value);
}
return json.toString();
} catch (final Exception e) {
LOG.error(e.getMessage());
return null;
}
}
示例13: handleConfigResponse
import org.codehaus.jettison.json.JSONObject; //导入方法依赖的package包/类
static JSONObject handleConfigResponse(JSONObject json, String section, String key) throws Exception {
if (section != null && "success".equals(CouchKey._c8oMeta.JSONObject(json).getString("status"))) {// modify json for schema compliance
JSONObject s = new JSONObject();
if (key == null) {
s.put(section, json);
} else {
JSONObject k = new JSONObject();
k.put(key, json.get("data"));
s.put(section, k);
}
s.put(CouchKey._c8oMeta.key(), json.remove(CouchKey._c8oMeta.key()));
return s;
}
return json;
}
示例14: indexOntology
import org.codehaus.jettison.json.JSONObject; //导入方法依赖的package包/类
@POST
@Consumes(MediaType.WILDCARD)
@Produces(MediaType.APPLICATION_JSON)
public Response indexOntology(IndexingJobInput input){
ResponseBuilder responseBuilder = null;
try {
String jid = ontonetHub.indexOntology(input);
URI location = URI.create(getPublicBaseUri() + "jobs/" + jid);
JSONObject jsonObject = new JSONObject();
try {
jsonObject.put("monitoringService", location.toString());
jsonObject.put("ontologyId", jid);
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
responseBuilder = Response.ok(jsonObject.toString());
} catch (OntologyAlreadyExistingException e1) {
responseBuilder = Response.status(Status.CONFLICT);
}
return responseBuilder.build();
}
示例15: putProperty
import org.codehaus.jettison.json.JSONObject; //导入方法依赖的package包/类
protected void putProperty(IonProperty property) {
try {
JSONObject jsonProperties = jsonBean.getJSONObject(Key.properties.name());
if (jsonProperties != null) {
jsonProperties.put(property.getName(), property.getJSONObject());
}
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}