當前位置: 首頁>>代碼示例>>Java>>正文


Java JSONObject.put方法代碼示例

本文整理匯總了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);
    }
}
 
開發者ID:gdibernardo,項目名稱:streaming-engines-benchmark,代碼行數:18,代碼來源:ResultProcessor.java

示例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;
}
 
開發者ID:marcocor,項目名稱:smaph,代碼行數:26,代碼來源:SmaphDebugger.java

示例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;
}
 
開發者ID:marcocor,項目名稱:smaph,代碼行數:22,代碼來源:SmaphDebugger.java

示例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;
}
 
開發者ID:marcocor,項目名稱:smaph,代碼行數:18,代碼來源:SmaphDebugger.java

示例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;
}
 
開發者ID:marcocor,項目名稱:smaph,代碼行數:17,代碼來源:SmaphDebugger.java

示例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();
	}
}
 
開發者ID:convertigo,項目名稱:convertigo-engine,代碼行數:19,代碼來源:PageComponent.java

示例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();
}
 
開發者ID:teamdigitale,項目名稱:ontonethub,代碼行數:31,代碼來源:OntonethubIndexingResource.java

示例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();
}
 
開發者ID:maltesander,項目名稱:rest-jersey2-json-jwt-authentication,代碼行數:15,代碼來源:ResponseBuilder.java

示例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);
}
 
開發者ID:react-dev26,項目名稱:NGB-master,代碼行數:13,代碼來源:VcfGa4ghReader.java

示例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;
}
 
開發者ID:convertigo,項目名稱:convertigo-eclipse,代碼行數:14,代碼來源:DesignDocumentFunctionTreeObject.java

示例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();

    }
 
開發者ID:yogykwan,項目名稱:mapreduce-samples,代碼行數:35,代碼來源:JSONConverter.java

示例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;
  }
}
 
開發者ID:stefanstaniAIM,項目名稱:IPPR2016,代碼行數:39,代碼來源:JsonComposer.java

示例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;
}
 
開發者ID:convertigo,項目名稱:convertigo-engine,代碼行數:16,代碼來源:GetServerConfigTransaction.java

示例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();
	
}
 
開發者ID:teamdigitale,項目名稱:ontonethub,代碼行數:31,代碼來源:OntonethubIndexingResource.java

示例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();
	}
}
 
開發者ID:convertigo,項目名稱:convertigo-engine,代碼行數:12,代碼來源:IonBean.java


注:本文中的org.codehaus.jettison.json.JSONObject.put方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。