本文整理匯總了Java中org.json.JSONObject.putOpt方法的典型用法代碼示例。如果您正苦於以下問題:Java JSONObject.putOpt方法的具體用法?Java JSONObject.putOpt怎麽用?Java JSONObject.putOpt使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.json.JSONObject
的用法示例。
在下文中一共展示了JSONObject.putOpt方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: toString
import org.json.JSONObject; //導入方法依賴的package包/類
@Override
public String toString() {
JSONObject jsonObject = new JSONObject();
try {
jsonObject.putOpt("code", code);
jsonObject.putOpt("message", message);
jsonObject.putOpt("mimeType", mimeType);
jsonObject.putOpt("name", name);
jsonObject.putOpt("fileSize", fileSize);
jsonObject.putOpt("createDate", createDate);
jsonObject.putOpt("hash", hash);
} catch (JSONException e) {
e.printStackTrace();
}
return jsonObject.toString();
}
示例2: onConnected
import org.json.JSONObject; //導入方法依賴的package包/類
@Override
public void onConnected(Call call) {
mCall = call;
JSONObject callProperties = new JSONObject();
try {
callProperties.putOpt("from", call.getFrom());
callProperties.putOpt("to", call.getTo());
callProperties.putOpt("callSid", call.getCallSid());
callProperties.putOpt("isMuted", call.isMuted());
String callState = getCallState(call.getState());
callProperties.putOpt("state",callState);
} catch (JSONException e) {
Log.e(TAG,e.getMessage(),e);
}
javascriptCallback("oncalldidconnect",callProperties,mInitCallbackContext);
}
示例3: buildRequest
import org.json.JSONObject; //導入方法依賴的package包/類
private Request buildRequest(String base64Photo, String apiService) {
JSONObject json = new JSONObject();
Log.i(TAG, "Kairos API call :\nSERVICE : "+apiService+" GALLERY : "+Kairos.GALLERY_VALUE);
try {
json.putOpt(Kairos.IMAGE, base64Photo);
json.putOpt(Kairos.GALLERY_NAME, Kairos.GALLERY_VALUE);
if(apiService.equals(Kairos.ENROLL)) {
Log.i(TAG, "SUBJECT : "+subject_id);
json.putOpt(Kairos.SUBJECT_ID, subject_id);
}
} catch(JSONException j) {
Log.i(TAG, "Problem in adding parameters to JSON");
j.printStackTrace();
}
RequestBody requestBody = RequestBody.create(JSON, json.toString());
Request request = new Request.Builder()
.url(Kairos.KAIROS_DOMAIN+"/"+apiService)
.addHeader(Kairos.APP_ID, Kairos.APP_ID_VALUE)
.addHeader(Kairos.APP_KEY, Kairos.APP_KEY_VALUE)
.addHeader(CONTENT, CONTENT_TYPE)
.post(requestBody)
.build();
return request;
}
示例4: toString
import org.json.JSONObject; //導入方法依賴的package包/類
@Override
public String toString() {
JSONObject jsonObject = new JSONObject();
try {
jsonObject.putOpt("offset", offset);
jsonObject.putOpt("context", context);
jsonObject.putOpt("crc32", crc32);
jsonObject.putOpt("md5", md5);
} catch (JSONException e) {
e.printStackTrace();
}
return jsonObject.toString();
}
示例5: call
import org.json.JSONObject; //導入方法依賴的package包/類
/**
* 主動調用h5方法
* @param jsonObject
*/
public void call(String handlerName,JSONObject jsonObject) {
JSONObject object = new JSONObject();
try {
object.putOpt("handlerName", handlerName);
object.putOpt("data", jsonObject);
} catch (JSONException e) {
e.printStackTrace();
}
final String execJs = String.format(CALLBACK_JS_FORMAT, String.valueOf(object));
Log.d("ss",execJs);
//如果activity已經關閉則不回調
if (mWebViewRef != null && mWebViewRef.get() != null ) {
if( mWebViewRef.get().getContext() instanceof Activity){
if (((Activity) mWebViewRef.get().getContext()).isFinishing()){
return;
}
}
mHandler.post(new Runnable() {
@Override
public void run() {
mWebViewRef.get().loadUrl(execJs);
}
});
}
}
示例6: setUp
import org.json.JSONObject; //導入方法依賴的package包/類
@Before
public void setUp() throws JSONException {
prefs = mContext.getSharedPreferences(STUDENT_PREFS, 0);
data = new JSONObject();
data.putOpt("username", "janedoe");
}
示例7: toString
import org.json.JSONObject; //導入方法依賴的package包/類
@Override
public String toString() {
JSONObject jsonObject = new JSONObject();
try {
jsonObject.putOpt("message", message);
jsonObject.putOpt("width", width);
jsonObject.putOpt("height", height);
jsonObject.putOpt("size", size);
jsonObject.putOpt("colorMode", colorMode);
} catch (JSONException e) {
e.printStackTrace();
}
return jsonObject.toString();
}
示例8: linkPing
import org.json.JSONObject; //導入方法依賴的package包/類
public String linkPing() {
if (!TextUtils.isEmpty(linkData)) {
return linkData;
}
JSONObject jsonObject = new JSONObject();
try {
jsonObject.putOpt("action", Action.LINK_ACTION);
jsonObject.putOpt("desc", "heart beat");
} catch (JSONException e) {
e.printStackTrace();
}
return linkData = jsonObject.toString();
}
示例9: jsonObjectPutAll
import org.json.JSONObject; //導入方法依賴的package包/類
static void jsonObjectPutAll(JSONObject jsonObject, Map<String, Object> map) {
Set<Map.Entry<String, Object>> entrySet = map.entrySet();
for (Map.Entry<String, Object> entry : entrySet) {
try {
jsonObject.putOpt(entry.getKey(), entry.getValue());
} catch (JSONException e) {
throw new IllegalArgumentException(e);
}
}
}
示例10: selectFile
import org.json.JSONObject; //導入方法依賴的package包/類
/**
* 選擇文件
*/
public static void selectFile(IQuickFragment webLoader, WebView wv, JSONObject param, Callback callback) {
try {
param.putOpt("className", FileChooseActivity.class.getName());
} catch (JSONException e) {
e.printStackTrace();
}
PageApi.openLocal(webLoader, wv, param, callback);
}
示例11: submit
import org.json.JSONObject; //導入方法依賴的package包/類
/**
* Submit a paste to the server.
*
* @see <a href="https://pastee.github.io/docs/#submit-a-new-paste">Pastee Docs: Submit a new paste</a>
* @param paste the paste to submit
*
* @return the response of the submit request
*/
public SubmitResponse submit(Paste paste) {
final String route = "/pastes";
JSONObject json = new JSONObject();
json.put("encrypted", paste.isEncrypted());
json.putOpt("description", paste.getDescription());
JSONArray sectionsJson = new JSONArray();
paste.getSections().forEach(section -> {
JSONObject sectionJson = new JSONObject();
sectionJson.putOpt("name", section.getName());
if(section.getSyntax() != null)
sectionJson.putOpt("syntax", section.getSyntax().getShortName());
sectionJson.put("contents", section.getContents());
sectionsJson.put(sectionJson);
});
json.put("sections", sectionsJson);
try {
return new SubmitResponse(post(route, json).getBody().getObject());
} catch(UnirestException e) {
return new SubmitResponse(e);
}
}
示例12: toJSONObject
import org.json.JSONObject; //導入方法依賴的package包/類
public JSONObject toJSONObject() {
JSONObject obj = new JSONObject();
try {
obj.put("id", this.id);
obj.putOpt("name", this.name);
obj.putOpt("email", this.email);
obj.putOpt("status", this.status);
} catch (JSONException e) {
throw new RuntimeException(e);
}
return obj;
}
示例13: javascriptErrorback
import org.json.JSONObject; //導入方法依賴的package包/類
private void javascriptErrorback(int errorCode, String errorMessage, CallbackContext callbackContext) {
JSONObject object = new JSONObject();
try {
object.putOpt("message", errorMessage);
} catch (JSONException e) {
callbackContext.sendPluginResult(new PluginResult(
PluginResult.Status.JSON_EXCEPTION));
return;
}
PluginResult result = new PluginResult(Status.ERROR, object);
result.setKeepCallback(true);
callbackContext.sendPluginResult(result);
}
示例14: getJSONObject
import org.json.JSONObject; //導入方法依賴的package包/類
/**
* 獲取callback返回數據json對象
*
* @param code 1:成功 0:失敗 2:下拉刷新回傳code值 3:頁麵刷新回傳code值
* @param msg 描述
* @param result
* @return
*/
public static JSONObject getJSONObject(int code, String msg, JSONObject result) {
JSONObject object = new JSONObject();
try {
object.put("code", code);
if (!TextUtils.isEmpty(msg)) {
object.put("msg", msg);
}
object.putOpt("result", result == null ? "" : result);
} catch (JSONException e) {
e.printStackTrace();
}
return object;
}
示例15: toJsonObject
import org.json.JSONObject; //導入方法依賴的package包/類
@NonNull
private JSONObject toJsonObject(@NonNull Target target) throws JSONException {
final JSONObject jsonObject = new JSONObject();
jsonObject.putOpt(TARGET_URL, target.getUrl());
return jsonObject;
}