本文整理汇总了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);
}
}
示例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();
}
示例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;
}
示例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;
}
}
示例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);
}
示例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;
}
示例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();
}
示例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);
}
示例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;
}