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