本文整理匯總了Java中org.json.simple.JSONObject.toJSONString方法的典型用法代碼示例。如果您正苦於以下問題:Java JSONObject.toJSONString方法的具體用法?Java JSONObject.toJSONString怎麽用?Java JSONObject.toJSONString使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.json.simple.JSONObject
的用法示例。
在下文中一共展示了JSONObject.toJSONString方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: updateCellName
import org.json.simple.JSONObject; //導入方法依賴的package包/類
/**
* セル名指定のセル更新のリクエスト実行.
* @param headers リクエストヘッダ
* @param requestBody リクエストボディ
* @param cellNameStr 更新前セル名
* @return Cell更新時のレスポンスオブジェクト
*/
private PersoniumResponse updateCellName(final HashMap<String, String> headers,
final JSONObject requestBody,
final String cellNameStr) {
PersoniumResponse ret = null;
PersoniumRestAdapter rest = new PersoniumRestAdapter();
String data = requestBody.toJSONString();
// リクエスト先のURL文字列を生成
StringBuilder url = new StringBuilder(UrlUtils.unitCtl(Cell.EDM_TYPE_NAME, cellNameStr));
try {
// リクエスト
ret = rest.put(url.toString(), data, headers);
} catch (Exception e) {
fail(e.getMessage());
}
return ret;
}
示例2: regbyphome
import org.json.simple.JSONObject; //導入方法依賴的package包/類
@RequestMapping(value="/regbyphone")
@ResponseBody
public String regbyphome(HttpServletRequest request){
String phone=request.getParameter("phone");
String pwd=StringUtil.md5(request.getParameter("pwd")+phone);
Map<String,Object> map=new HashMap<String,Object>();
if(!regbyphone.phoneValid(phone)){
map.put("messagecode", 205);
map.put("message", "失敗(手機號已被注冊)");
map.put("guid", "");
return JSONObject.toJSONString(map);
}else{
String guid=regbyphone.newGuid();
map.put("messagecode", 200);
map.put("message", "成功");
map.put("guid",guid);
regbyphone.reg(phone, pwd, guid);
return JSONObject.toJSONString(map);
}
}
示例3: createExtRole
import org.json.simple.JSONObject; //導入方法依賴的package包/類
/**
* 30_$extroles.jsonに定義されているExtRole情報をESへ登録する.
* @param json JSONファイルから読み込んだJSONオブジェクト
*/
@SuppressWarnings("unchecked")
private void createExtRole(JSONObject json) {
String url = (String) json.get(ExtRole.EDM_TYPE_NAME);
json.put(ExtRole.EDM_TYPE_NAME, url);
json.put("_Relation._Box.Name", createdBoxName);
StringReader stringReader = new StringReader(json.toJSONString());
odataEntityResource.setEntitySetName(ExtRole.EDM_TYPE_NAME);
OEntityWrapper oew = odataEntityResource.getOEntityWrapper(stringReader,
odataEntityResource.getOdataResource(),
CtlSchema.getEdmDataServicesForCellCtl().build());
// ExtRoleの登録
odataProducer.
createEntity(ExtRole.EDM_TYPE_NAME, oew);
}
示例4: createHar
import org.json.simple.JSONObject; //導入方法依賴的package包/類
@SuppressWarnings("rawtypes")
private void createHar(String pt, String rt) {
Har<String, Log> har = new Har<>();
Page p = new Page(pt, har.pages());
har.addPage(p);
for (Object res : (JSONArray) JSONValue.parse(rt)) {
JSONObject jse = (JSONObject) res;
if (jse.size() > 14) {
Entry e = new Entry(jse.toJSONString(), p);
har.addEntry(e);
}
}
har.addRaw(pt, rt);
Control.ReportManager.addHar(har, (TestCaseReport) Report,
escapeName(Data));
}
示例5: getReceivedMessageBody
import org.json.simple.JSONObject; //導入方法依賴的package包/類
/**
* メッセージ受信用Bodyの取得.
* @param type メッセージ種別
* @param id 受信メッセージのID
* @return メッセージボディ
*/
@SuppressWarnings("unchecked")
protected String getReceivedMessageBody(final String type, final String id) {
String status = null;
if ("message".equals(type)) {
status = "unread";
} else if ("req.relation.build".equals(type) || "req.relation.break".equals(type)) {
status = "none";
} else {
status = "unread";
}
JSONObject body = new JSONObject();
body.put("__id", id);
body.put("From", UrlUtils.cellRoot(Setup.TEST_CELL2));
body.put("Type", type);
body.put("Title", "Title");
body.put("Body", "Body");
body.put("Priority", 3);
body.put("Status", status);
body.put("RequestRelation", "user");
body.put("RequestRelationTarget", UrlUtils.cellRoot("targetCell"));
return body.toJSONString();
}
示例6: TestEventResource
import org.json.simple.JSONObject; //導入方法依賴的package包/類
/**
* リクエストボディのresultが文字列型上限値の場合に正常終了すること.
*/
@Test
@SuppressWarnings("unchecked")
public void リクエストボディのresultが文字列型上限値の場合に正常終了すること() {
TestEventResource resource = new TestEventResource();
JSONObject body = createEventBody();
StringBuilder newValue = new StringBuilder();
for (int i = 0; i < Common.MAX_EVENT_VALUE_LENGTH; i++) {
newValue.append("a");
}
body.put("result", newValue.toString());
StringReader reader = new StringReader(body.toJSONString());
JSONEvent event = resource.getRequestBody(reader);
resource.validateEventProperties(event);
assertEquals("INFO", event.getLevel().toString());
assertEquals("POST", event.getAction());
assertEquals("ObjectData", event.getObject());
assertEquals(newValue.toString(), event.getResult());
}
示例7: createCell
import org.json.simple.JSONObject; //導入方法依賴的package包/類
/**
* Cell作成.
* @param cellName Cell名
* @return Cell作成時のレスポンスオブジェクト
*/
@SuppressWarnings("unchecked")
public final PersoniumResponse createCell(final String cellName) {
PersoniumRestAdapter rest = new PersoniumRestAdapter();
PersoniumResponse res = null;
// リクエストヘッダをセット
HashMap<String, String> requestheaders = new HashMap<String, String>();
requestheaders.put(HttpHeaders.AUTHORIZATION, BEARER_MASTER_TOKEN);
// リクエストボディを生成
JSONObject requestBody = new JSONObject();
requestBody.put("Name", cellName);
String data = requestBody.toJSONString();
// リクエスト
try {
res = rest.post(UrlUtils.unitCtl(Cell.EDM_TYPE_NAME), data, requestheaders);
} catch (Exception e) {
fail(e.getMessage());
}
return res;
}
示例8: resolvePortNames
import org.json.simple.JSONObject; //導入方法依賴的package包/類
private String resolvePortNames(String metricsSnapshot) {
if (metricsSnapshot != null) {
JSONParser parser = new JSONParser();
try {
JSONObject metricsObject = (JSONObject) parser.parse(metricsSnapshot);
JSONArray peArray = (JSONArray) metricsObject.get("pes");
for (int i = 0; i < peArray.size(); i++) {
JSONObject pe = (JSONObject) peArray.get(i);
// resolvePeInputPortNames(pe);
// resolvePeOutputPortNames(pe);
JSONArray operatorArray = (JSONArray) pe.get("operators");
for (int j = 0; j < operatorArray.size(); j++) {
JSONObject operator = (JSONObject) operatorArray.get(j);
resolveOperatorInputPortNames(operator);
resolveOperatorOutputPortNames(operator);
}
}
metricsSnapshot = metricsObject.toJSONString();
} catch (ParseException e) {
throw new IllegalStateException(e);
}
}
return metricsSnapshot;
}
示例9: createKernelJSON
import org.json.simple.JSONObject; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
public static String createKernelJSON(String classpath, String logLevel, String javaBinaryPath) {
JSONObject root = new JSONObject();
root.put("language", ScijavaEvaluator.DEFAULT_LANGUAGE);
root.put("display_name", "SciJava");
JSONArray argv = new JSONArray();
if (javaBinaryPath == null) {
argv.add(SystemUtil.getJavaBinary());
} else {
argv.add(javaBinaryPath);
}
argv.add("-classpath");
String finalClasspath = "";
finalClasspath += SystemUtil.getImageJClassPaths();
String classPathSeparator = SystemUtil.getClassPathSeparator();
if (classpath != null) {
if (finalClasspath.length() > 0) {
finalClasspath += classPathSeparator + classpath;
} else {
finalClasspath += classpath;
}
}
argv.add(finalClasspath);
argv.add("org.scijava.jupyter.kernel.ScijavaKernel");
argv.add("-verbose");
argv.add(logLevel);
argv.add("-connectionFile");
argv.add("{connection_file}");
root.put("argv", argv);
return root.toJSONString();
}
示例10: createRole
import org.json.simple.JSONObject; //導入方法依賴的package包/類
/**
* 20_$roles.jsonに定義されているRole情報をESへ登録する.
* @param json JSONファイルから読み込んだJSONオブジェクト
*/
@SuppressWarnings("unchecked")
private void createRole(JSONObject json) {
json.put("_Box.Name", createdBoxName);
StringReader stringReader = new StringReader(json.toJSONString());
odataEntityResource.setEntitySetName(Role.EDM_TYPE_NAME);
OEntityWrapper oew = odataEntityResource.getOEntityWrapper(stringReader,
odataEntityResource.getOdataResource(),
CtlSchema.getEdmDataServicesForCellCtl().build());
// Roleの登録
odataProducer.
createEntity(Role.EDM_TYPE_NAME, oew);
}
示例11: createJsonBody
import org.json.simple.JSONObject; //導入方法依賴的package包/類
/**
* Json形式のエラーメッセージを作成する.
* @param exception PersoniumCoreException
* @return レスポンスボディ用Json形式エラーメッセージ
*/
private String createJsonBody(PersoniumCoreException exception) {
String code = exception.getCode();
String message = exception.getMessage();
LinkedHashMap<String, Object> json = new LinkedHashMap<String, Object>();
LinkedHashMap<String, Object> jsonMessage = new LinkedHashMap<String, Object>();
json.put("code", code);
jsonMessage.put("lang", ODataErrorMessage.DEFAULT_LANG_TAG);
jsonMessage.put("value", message);
json.put("message", jsonMessage);
return JSONObject.toJSONString(json);
}
示例12: toString
import org.json.simple.JSONObject; //導入方法依賴的package包/類
@Override
public String toString() {
JSONObject json = new JSONObject();
json.put("id", id);
json.put("firstName", first_name);
json.put("lastName", last_name);
json.put("password", password);
json.put("phone", phone);
json.put("account", account);
json.put("picture", picture);
json.put("email", email);
return json.toJSONString();
}
示例13: toString
import org.json.simple.JSONObject; //導入方法依賴的package包/類
@Override
public String toString() {
JSONObject data = new JSONObject();
data.put("name", url);
data.put("score", insights.size() > 0 && score >= 0 ? score / insights.size() : score);
data.put("logs", insights);
return data.toJSONString();
}
示例14: get
import org.json.simple.JSONObject; //導入方法依賴的package包/類
/**
* GET method.
* @return JAX-RS Response
*/
@GET
public Response get() {
// Check the authority required for execution.
cellRsCmp.checkAccessContext(cellRsCmp.getAccessContext(), CellPrivilege.ROOT);
String jsonString = "";
if (Cell.STATUS_NORMAL.equals(cellRsCmp.getDavCmp().getCellStatus())) {
// Get processing status from cache.
// If it returns null, it is regarded as ready state.
String key = SnapshotFileImportProgressInfo.getKey(cellRsCmp.getCell().getId());
Progress progress = ProgressManager.getProgress(key);
if (progress == null) {
JSONObject response = SnapshotFileImportProgressInfo.getReadyJson();
jsonString = response.toJSONString();
} else {
jsonString = progress.getValue();
}
} else {
// Get status from error file.
Path errorFilePath = Paths.get(PersoniumUnitConfig.getBlobStoreRoot(),
cellRsCmp.getCell().getDataBundleName(), cellRsCmp.getCell().getId(), Cell.IMPORT_ERROR_FILE_NAME);
try {
jsonString = new String(Files.readAllBytes(errorFilePath), Charsets.UTF_8);
} catch (IOException e) {
throw PersoniumCoreException.Common.FILE_IO_ERROR.params("read error json file").reason(e);
}
}
return Response.ok().entity(jsonString).build();
}
示例15: createBox
import org.json.simple.JSONObject; //導入方法依賴的package包/類
/**
* Box情報をESへ登録する.
* @param json JSONファイルから読み込んだJSONオブジェクト
*/
@SuppressWarnings("unchecked")
void createBox(JSONObject json) {
if (boxName == null || boxName.isEmpty()) {
this.createdBoxName = (String) json.get("Name");
} else {
json.put("Name", boxName);
this.createdBoxName = boxName;
}
StringReader stringReader = new StringReader(json.toJSONString());
OEntityWrapper oew = odataEntityResource.getOEntityWrapper(stringReader,
odataEntityResource.getOdataResource(),
CtlSchema.getEdmDataServicesForCellCtl().build());
// Boxの登録
odataProducer.
createEntity(entitySetName, oew);
this.createdBoxEtag = oew.getEtag();
// Davの登録
Box newBox = new Box(odataEntityResource.getAccessContext().getCell(), oew);
this.boxCmp = ModelFactory.boxCmp(newBox);
this.box = newBox;
this.schemaUrl = (String) json.get("Schema");
}