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


Java JSONObject.toString方法代碼示例

本文整理匯總了Java中org.codehaus.jettison.json.JSONObject.toString方法的典型用法代碼示例。如果您正苦於以下問題:Java JSONObject.toString方法的具體用法?Java JSONObject.toString怎麽用?Java JSONObject.toString使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.codehaus.jettison.json.JSONObject的用法示例。


在下文中一共展示了JSONObject.toString方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: run

import org.codehaus.jettison.json.JSONObject; //導入方法依賴的package包/類
public void run(String serviceName, HttpServletRequest request, HttpServletResponse response) throws ServiceException {
       try {
       	response.setContentType(MimeType.JavascriptDeprecated.value());
       	response.setCharacterEncoding("UTF-8");
       	
		JSONObject json = new JSONObject();
		
           getServiceResult(request, json);
           String sJSON = json.toString();
           response.getWriter().write(sJSON);
           
		Engine.logAdmin.debug("JSON generated:\n" + sJSON);
       } catch (Throwable t) {
		ServiceUtils.handleError(t, response);
	}
}
 
開發者ID:convertigo,項目名稱:convertigo-engine,代碼行數:17,代碼來源:JSonService.java

示例2: encodeResponseJson

import org.codehaus.jettison.json.JSONObject; //導入方法依賴的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();
}
 
開發者ID:marcocor,項目名稱:smaph,代碼行數:31,代碼來源:SmaphServlet.java

示例3: getJSONValue

import org.codehaus.jettison.json.JSONObject; //導入方法依賴的package包/類
private String getJSONValue() {
	String connectorName = getComboConnectorName();
	String requestableName = getComboRequestableName();
	String eventName = getTextEventName();
	
	if (connectorName.equals("") && requestableName.equals("") && eventName.equals(""))
		return "";
	
	try {
		JSONObject jsonob = new JSONObject();
		if (!connectorName.equals("") || !requestableName.equals("")) {
			JSONObject jsonr = new JSONObject();
			if (!requestableName.equals(""))
				jsonr.accumulate((connectorName.equals("") ? Parameter.Sequence.getName():Parameter.Transaction.getName()), requestableName);
			if (!connectorName.equals(""))
				jsonr.accumulate(Parameter.Connector.getName(), connectorName);
			jsonob.accumulate("requestable", jsonr);
		}
		if (!eventName.equals(""))
			jsonob.accumulate("event", eventName);
		
		return jsonob.toString();
		
	} catch (JSONException e) {
		ConvertigoPlugin.logException(e, "Unable to set mashup event value", Boolean.TRUE);
	}
	return value;
}
 
開發者ID:convertigo,項目名稱:convertigo-eclipse,代碼行數:29,代碼來源:JavelinMashupEventEditorComposite.java

示例4: 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

示例5: save

import org.codehaus.jettison.json.JSONObject; //導入方法依賴的package包/類
private void save(JSONObject db) throws IOException {
	String json = db.toString();
	cache = db;
	byte[] data = json.getBytes("UTF-8");
	data = Crypto2.encodeToByteArray(EnginePropertiesManager.getProperty(PropertyName.CRYPTO_PASSPHRASE), data);
	FileUtils.writeByteArrayToFile(new File(Engine.CONFIGURATION_PATH + "/user_roles.db"), data);
}
 
開發者ID:convertigo,項目名稱:convertigo-engine,代碼行數:8,代碼來源:AuthenticatedSessionManager.java

示例6: XmlToJson

import org.codehaus.jettison.json.JSONObject; //導入方法依賴的package包/類
public static String XmlToJson(Element elt, boolean ignoreStepIds, boolean useType, JsonRoot jsonRoot) throws JSONException {
	JSONObject json = new JSONObject();
	handleElement(elt, json, ignoreStepIds, useType);
	String jsonString =   json.toString(1);
	if (jsonRoot != null && !jsonRoot.equals(JsonRoot.docNode)) {
		JSONObject jso = new JSONObject(jsonString).getJSONObject(elt.getTagName());
		if (jsonRoot.equals(JsonRoot.docChildNodes)) {
			jso.remove("attr");
		}
		jsonString = jso.toString(1);
	}
	return jsonString;
}
 
開發者ID:convertigo,項目名稱:convertigo-engine,代碼行數:14,代碼來源:XMLUtils.java

示例7: genBuildOutput

import org.codehaus.jettison.json.JSONObject; //導入方法依賴的package包/類
private String genBuildOutput(Result buildResult) throws JSONException {
  JSONObject buildOutputJsonObj = new JSONObject();
  buildOutputJsonObj.put("result", buildResult.getResult());
  buildOutputJsonObj.put("error", buildResult.getError());
  buildOutputJsonObj.put("output", buildResult.getOutput());
  if (buildResult.getFormName() != null) {
    buildOutputJsonObj.put("formName", buildResult.getFormName());
  }
  return buildOutputJsonObj.toString();
}
 
開發者ID:mit-cml,項目名稱:appinventor-extensions,代碼行數:11,代碼來源:BuildServer.java

示例8: addInfos

import org.codehaus.jettison.json.JSONObject; //導入方法依賴的package包/類
@Override
protected void addInfos(Map<String, Set<String>> infoMap) {
	IonBean ionBean = getIonBean();
	if (ionBean != null) {
		String beanName = ionBean.getName(); 
		if (ionBean.hasProperty("marker")) {
			JSONObject json = new JSONObject();
			String key = null;
			
			for (IonProperty property : ionBean.getProperties().values()) {
				MobileSmartSourceType msst = property.getSmartType();
				String p_name = property.getName();
				Object p_value = property.getValue();
				
				if (!p_value.equals(false)) {
					if (beanName.equals("FullSyncViewAction")) {
						if (p_name.equals("fsview")) {
							key = p_value.toString() + ".view";
						}
					} else if (beanName.equals("CallSequenceAction")) {
						if (p_name.equals("requestable")) {
							key = p_value.toString();
						}
					} else if (beanName.equals("CallFullSyncAction")) {
						if (p_name.equals("requestable")) {
							key = p_value.toString();
							Object p_verb = ionBean.getProperty("verb").getValue();
							if (!p_verb.equals(false)) {
								key += "."+ p_verb.toString();
							}
						}
					}
				}
				
				try {
					if (p_name.equals("marker")) {
						json.put(p_name, !p_value.equals(false) ? msst.getValue():"");
					}
					if (p_name.equals("include_docs")) {
						json.put(p_name, !p_value.equals(false) ? msst.getValue():"false");
					}
				} catch (JSONException e) {
					e.printStackTrace();
				}
			}
			
			if (key != null && !key.isEmpty()) {
				Set<String> infos = infoMap.get(key);
				if (infos == null) {
					infos = new HashSet<String>();
				}
				String info = json.toString();
				if (!info.isEmpty()) {
					infos.add(info);
				}
				infoMap.put(key, infos);
			}
		}
	}
	
	super.addInfos(infoMap);
}
 
開發者ID:convertigo,項目名稱:convertigo-engine,代碼行數:63,代碼來源:UIDynamicAction.java

示例9: toBeanData

import org.codehaus.jettison.json.JSONObject; //導入方法依賴的package包/類
public String toBeanData() {
	String s = jsonBean.toString();
	try {
		JSONObject jsonOb = new JSONObject(toString());
		for (Key k: Key.values()) {
			if (k.equals(Key.name))
				continue;
			if (k.equals(Key.properties)) {
				JSONObject jsonProperties = jsonOb.getJSONObject(Key.properties.name());
				if (jsonProperties != null) {
					@SuppressWarnings("unchecked")
					Iterator<String> it = jsonProperties.keys();
					while (it.hasNext()) {
						String pkey = it.next();
						if (!pkey.isEmpty()) {
							Object ob = jsonProperties.get(pkey);
							if (ob instanceof JSONObject) {
								JSONObject jsonProperty = (JSONObject)ob;
								for (IonProperty.Key kp: IonProperty.Key.values()) {
									if (kp.equals(IonProperty.Key.name)) continue;
									if (kp.equals(IonProperty.Key.mode)) continue;
									if (kp.equals(IonProperty.Key.value)) continue;
									jsonProperty.remove(kp.name());
								}
								jsonProperties.put(pkey, jsonProperty);
							}
						}
					}
					jsonOb.put(Key.properties.name(), jsonProperties);
					continue;
				}
			}
			jsonOb.remove(k.name());
		}
		s = jsonOb.toString();
	} catch (JSONException e) {
		e.printStackTrace();
	}
	//System.out.println(s);
	return s;
}
 
開發者ID:convertigo,項目名稱:convertigo-engine,代碼行數:42,代碼來源:IonBean.java


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