本文整理汇总了Java中sagex.remote.json.JSONObject.put方法的典型用法代码示例。如果您正苦于以下问题:Java JSONObject.put方法的具体用法?Java JSONObject.put怎么用?Java JSONObject.put使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sagex.remote.json.JSONObject
的用法示例。
在下文中一共展示了JSONObject.put方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: encodeError
import sagex.remote.json.JSONObject; //导入方法依赖的package包/类
public String encodeError(Exception e) {
try {
JSONObject jo = new JSONObject();
jo.put("sagexVersion", sagex.api.Version.GetVersion());
jo.put("error", e.getMessage());
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
e.printStackTrace(pw);
pw.flush();
jo.put("exception", sw.toString());
StringWriter sw2 = new StringWriter();
jo.write(sw2);
return sw2.toString();
} catch (Exception ex) {
return "{error: " + e.getMessage() + "}";
}
}
示例2: getState
import sagex.remote.json.JSONObject; //导入方法依赖的package包/类
/**
* Returns the current state of the view.
*
* @param folder
* @return
* @throws IOException
*/
public String getState(ViewFolder folder) throws IOException {
JSONObject viewState = new JSONObject();
try {
ViewFactory fact = folder.getViewFactory();
viewState.put("view", fact.getName());
JSONArray presentations = new JSONArray();
if (fact.getViewPresentations().size() > 0) {
List<ViewPresentation> list = new ArrayList<ViewPresentation>(fact.getViewPresentations());
for (int i = 0; i < list.size(); i++) {
presentations.put(serializePresentation(list.get(i)));
}
}
viewState.put("presentations", presentations);
} catch (JSONException e) {
throw new IOException("Failed to store ");
}
return viewState.toString();
}
示例3: serializeConfigurable
import sagex.remote.json.JSONObject; //导入方法依赖的package包/类
private JSONObject serializeConfigurable(BaseConfigurable conf) throws JSONException {
JSONObject jo = new JSONObject();
jo.put("name", ((HasName) conf).getName());
JSONArray optArr = new JSONArray();
jo.put("options", optArr);
for (String s : conf.getOptionNames()) {
if ("name".equals(s))
continue;
ConfigurableOption co = conf.getOption(s);
if (!StringUtils.isEmpty(co.value().getValue())) {
JSONObject opt = new JSONObject();
opt.put("name", co.getName());
opt.put("value", co.value().getValue());
optArr.put(opt);
}
}
return jo;
}
示例4: createJSONApiString
import sagex.remote.json.JSONObject; //导入方法依赖的package包/类
private String createJSONApiString(List<ClassMetadata> allClasses2) {
try {
JSONObject jo = new JSONObject();
for (ClassMetadata md : allClasses2) {
jo.put(md.name, new JSONObject(md));
}
StringWriter sw = new StringWriter();
jo.write(sw);
return sw.toString();
} catch (Exception e) {
return "{}";
}
}