本文整理匯總了Java中org.json.JSONObject.put方法的典型用法代碼示例。如果您正苦於以下問題:Java JSONObject.put方法的具體用法?Java JSONObject.put怎麽用?Java JSONObject.put使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.json.JSONObject
的用法示例。
在下文中一共展示了JSONObject.put方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: uploadContents
import org.json.JSONObject; //導入方法依賴的package包/類
public String uploadContents(String contents) throws Exception {
if (!rootJson.has("appkey") || !rootJson.has("timestamp") || !rootJson.has("validation_token")) {
throw new Exception("appkey, timestamp and validation_token needs to be set.");
}
// Construct the json string
JSONObject uploadJson = new JSONObject();
uploadJson.put("appkey", rootJson.getString("appkey"));
uploadJson.put("timestamp", rootJson.getString("timestamp"));
uploadJson.put("validation_token", rootJson.getString("validation_token"));
uploadJson.put("content", contents);
// Construct the request
String url = host + uploadPath;
HttpPost post = new HttpPost(url);
post.setHeader("User-Agent", USER_AGENT);
StringEntity se = new StringEntity(uploadJson.toString(), "UTF-8");
post.setEntity(se);
// Send the post request and get the response
HttpResponse response = client.execute(post);
System.out.println("Response Code : " + response.getStatusLine().getStatusCode());
BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
StringBuffer result = new StringBuffer();
String line = "";
while ((line = rd.readLine()) != null) {
result.append(line);
}
System.out.println(result.toString());
// Decode response string and get file_id from it
JSONObject respJson = new JSONObject(result.toString());
String ret = respJson.getString("ret");
if (!ret.equals("SUCCESS")) {
throw new Exception("Failed to upload file");
}
JSONObject data = respJson.getJSONObject("data");
String fileId = data.getString("file_id");
// Set file_id into rootJson using setPredefinedKeyValue
setPredefinedKeyValue("file_id", fileId);
return fileId;
}
示例2: senOTPJson
import org.json.JSONObject; //導入方法依賴的package包/類
private boolean senOTPJson(String mobile) {
JSONObject json = new JSONObject();
try {
json.put("PPHONENUMBER", mobile);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
return false;
}
if (comman.isNetworkAvailable(context)) {
sendOTPWebServiceProcess(json);
} else {
comman.alertDialog(VerifyOTP.this, getString(R.string.no_internet_connection),getString(R.string.you_dont_have_internet));
}
return true;
}
示例3: encodingMap
import org.json.JSONObject; //導入方法依賴的package包/類
private static JSONObject encodingMap(Object bean){
JSONObject jsonObject = new JSONObject();
Map<String,Object> map = (Map)bean;
try {
for (String key : map.keySet()) {
Object item = map.get(key);
JsonEncodeType type=getEncodingType(item);
//LogUtil.e("json","name="+key+",type="+type);
if(JsonEncodeType.Normal == type) {
jsonObject.put(key, item);
}else if(JsonEncodeType.List == type){
jsonObject.put(key, encodingList(item));
}else if(JsonEncodeType.Array == type){
jsonObject.put(key, encodingArray(item));
}else if(JsonEncodeType.Map == type){
jsonObject.put(key, encodingMap(item));
}else {
jsonObject.put(key, encodingObject(item));
}
}
}catch (JSONException e) {
LogUtils.e(e);
}
return jsonObject;
}
示例4: sendModifyChatRoomName
import org.json.JSONObject; //導入方法依賴的package包/類
/**
*
* 修改群聊天名稱
*
* @Description<功能詳細描述>
*
* @param task
* @param handler
* @param requestType
* @param cid
* @param name
* @return
* @LastModifiedDate:2017年3月28日
* @author wl
* @EditHistory:<修改內容><修改人>
*/
public static NetTask sendModifyChatRoomName(NetTask task, Handler handler, int requestType, String cid, String name)
{
JSONObject bodyVaule = new JSONObject();
try
{
bodyVaule.put("cid", cid);
bodyVaule.put("name", name);
}
catch (JSONException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
JSONObject requestObj =
NetRequestController.getPredefineObj("chat", "ChatAdapter", "modifyChatRoomName", "general", bodyVaule);
return NetRequestController.sendStrBaseServlet(task, handler, requestType, requestObj);
}
示例5: toJSON
import org.json.JSONObject; //導入方法依賴的package包/類
/**
* Write chain to JSONObject.
* For debugging only.
*
* @return JSONObject
*
*/
public JSONObject toJSON() {
try {
JSONObject obj = new JSONObject();
obj.put("path", getPath());
JSONArray addresses = new JSONArray();
for(int i = 0; i < 2; i++) {
Address addr = new Address(params, cKey, i);
addresses.put(addr.toJSON());
}
obj.put("addresses", addresses);
return obj;
}
catch(JSONException ex) {
throw new RuntimeException(ex);
}
}
示例6: onPageFinished
import org.json.JSONObject; //導入方法依賴的package包/類
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
// CB-10395 InAppBrowser's WebView not storing cookies reliable to local device storage
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) {
CookieManager.getInstance().flush();
} else {
CookieSyncManager.getInstance().sync();
}
// https://issues.apache.org/jira/browse/CB-11248
view.clearFocus();
view.requestFocus();
try {
JSONObject obj = new JSONObject();
obj.put("type", LOAD_STOP_EVENT);
obj.put("url", url);
sendUpdate(obj, true);
} catch (JSONException ex) {
LOG.d(LOG_TAG, "Should never happen");
}
}
示例7: testGetLatestEventResultWhenFirstObjectIsntWithLatestDate
import org.json.JSONObject; //導入方法依賴的package包/類
@Test
public void testGetLatestEventResultWhenFirstObjectIsntWithLatestDate() throws JSONException {
JSONArray array = new JSONArray();
JSONObject firstJsonObject = new JSONObject();
firstJsonObject.put("id", "455");
firstJsonObject.put("rk", COM_OPENSOURCE_QUALITY_GATES);
firstJsonObject.put("n", GREEN_WAS_RED);
firstJsonObject.put("c", ALERT);
firstJsonObject.put(DT, T12_01_31_0100);
firstJsonObject.put("ds", "");
JSONObject secondJsonObject = new JSONObject();
secondJsonObject.put("id", "456");
secondJsonObject.put("rk", COM_OPENSOURCE_QUALITY_GATES);
secondJsonObject.put("n", GREEN_WAS_RED);
secondJsonObject.put("c", ALERT);
secondJsonObject.put(DT, "2016-03-26T12:01:31+0100");
secondJsonObject.put("ds", "");
array.put(firstJsonObject);
array.put(secondJsonObject);
assertEquals(secondJsonObject.toString(), qualityGateResponseParser.getLatestEventResult(array).toString());
}
示例8: convertToJSON
import org.json.JSONObject; //導入方法依賴的package包/類
public static JSONObject convertToJSON(Bundle bundle) throws JSONException {
JSONObject json = new JSONObject();
for(String key : bundle.keySet()) {
Object value = bundle.get(key);
if (value == null) {
// Null is not supported.
continue;
}
// Special case List<String> as getClass would not work, since List is an interface
if (value instanceof List<?>) {
JSONArray jsonArray = new JSONArray();
@SuppressWarnings("unchecked")
List<String> listValue = (List<String>)value;
for (String stringValue : listValue) {
jsonArray.put(stringValue);
}
json.put(key, jsonArray);
continue;
}
// Special case Bundle as it's one way, on the return it will be JSONObject
if (value instanceof Bundle) {
json.put(key, convertToJSON((Bundle)value));
continue;
}
Setter setter = SETTERS.get(value.getClass());
if (setter == null) {
throw new IllegalArgumentException("Unsupported type: " + value.getClass());
}
setter.setOnJSON(json, key, value);
}
return json;
}
示例9: toJson
import org.json.JSONObject; //導入方法依賴的package包/類
@NonNull
String toJson() throws JSONException {
JSONObject res = new JSONObject();
JSONArray a1 = new JSONArray();
a1.put(start.latitude);
a1.put(start.longitude);
JSONArray a2 = new JSONArray();
a2.put(end.latitude);
a2.put(end.longitude);
res.put("start", a1);
res.put("end", a2);
res.put("distance", distance);
return res.toString();
}
示例10: a
import org.json.JSONObject; //導入方法依賴的package包/類
public boolean a(JSONObject jSONObject) {
if (this.e != null) {
jSONObject.put("ut", this.e.getUserType());
}
if (this.l != null) {
jSONObject.put("cfg", this.l);
}
this.a.a(jSONObject);
return true;
}
示例11: getBumpAsJSONObject
import org.json.JSONObject; //導入方法依賴的package包/類
public JSONObject getBumpAsJSONObject() {
JSONObject object = new JSONObject();
try {
object.put("coords", StringUtil.getStringFromCoords(new double[]{getLatitude(), getLongitude(), getAltitude()}));
object.put("acc", StringUtil.getStringFromCoords(new double[]{getAccelerationX(), getAccelerationY(), getAccelerationZ()}));
object.put("time", DateUtil.format(new Date(getTime()), DateUtil.Format.SERVER_DATE));
object.put("speed", getSpeed());
object.put("is_fixed", isFixed());
} catch (JSONException e) {
}
return object;
}
示例12: sendResetUrl
import org.json.JSONObject; //導入方法依賴的package包/類
/**
* Sends the password resetting URL with a random token.
*
* @param userEmail
* the given email
* @param jsonObject
* return code and message object
* @throws JSONException
* the JSONException
* @throws ServiceException
* the ServiceException
* @throws IOException
* the IOException
* @throws RepositoryException
* the RepositoryException
*/
private void sendResetUrl(final String userEmail, final JSONObject jsonObject)
throws JSONException, ServiceException, IOException, RepositoryException {
final JSONObject preference = preferenceQueryService.getPreference();
final String token = new Randoms().nextStringWithMD5();
final String adminEmail = preference.getString(Option.ID_C_ADMIN_EMAIL);
final String mailSubject = langPropsService.get("resetPwdMailSubject");
final String mailBody = langPropsService.get("resetPwdMailBody") + " " + Latkes.getServePath()
+ "/forgot?token=" + token + "&login=" + userEmail;
final MailMessage message = new MailMessage();
final JSONObject option = new JSONObject();
option.put(Keys.OBJECT_ID, token);
option.put(Option.OPTION_CATEGORY, "passwordReset");
option.put(Option.OPTION_VALUE, System.currentTimeMillis());
// final Transaction transaction = optionRepository.beginTransaction();
optionRepository.add(option);
// transaction.commit();
message.setFrom(adminEmail);
message.addRecipient(userEmail);
message.setSubject(mailSubject);
message.setHtmlBody(mailBody);
mailService.send(message);
jsonObject.put("succeed", true);
jsonObject.put("to", Latkes.getServePath() + "/login?from=forgot");
jsonObject.put(Keys.MSG, langPropsService.get("resetPwdSuccessSend"));
logger.debug("Sent a mail[mailSubject={}, mailBody=[{}] to [{}]", mailSubject, mailBody, userEmail);
}
示例13: getJsonBody
import org.json.JSONObject; //導入方法依賴的package包/類
private String getJsonBody(String email, String className, String examName, String groupsClass) {
JSONObject jsonObject = new JSONObject();
try {
jsonObject.put("email", email);
jsonObject.put("userClassName", className);
jsonObject.put("name", examName);
jsonObject.put("groups", groupsClass);
} catch (JSONException e) {
e.printStackTrace();
}
return jsonObject.toString();
}
示例14: SusiThought
import org.json.JSONObject; //導入方法依賴的package包/類
/**
* Create an initial thought using the matcher on an expression.
* Such an expression is like the input from a text source which contains keywords
* that are essential for the thought. The matcher extracts such information.
* Matching informations are named using the order of the appearance of the information pieces.
* The first information is named '1', the second '2' and so on. The whole information which contained
* the matching information is named '0'.
* @param matcher
*/
public SusiThought(Matcher matcher) {
this();
this.setOffset(0).setHits(1);
JSONObject row = new JSONObject();
row.put("0", matcher.group(0));
for (int i = 0; i < matcher.groupCount(); i++) {
row.put(Integer.toString(i + 1), matcher.group(i + 1));
}
this.setData(new JSONArray().put(row));
}
示例15: b
import org.json.JSONObject; //導入方法依賴的package包/類
public static String b(Context context, String str) {
String str2 = VERSION.RELEASE + "," + Integer.toString(VERSION.SDK_INT);
String str3 = Build.MODEL;
String a = s.a(context, z[79], z[76]);
String str4 = Build.DEVICE;
Object F = cn.jpush.android.a.F();
if (ai.a(F)) {
F = " ";
}
String c = c(context);
JSONObject jSONObject = new JSONObject();
try {
jSONObject.put(z[TransportMediator.KEYCODE_MEDIA_PLAY], str2);
jSONObject.put(z[LeMessageIds.MSG_ALBUM_FETCH_PLAY_NEXT_CONTROLLER], str3);
jSONObject.put(z[76], a);
jSONObject.put(z[122], str4);
jSONObject.put(z[125], F);
jSONObject.put(z[123], c);
jSONObject.put(z[124], str);
} catch (JSONException e) {
}
return jSONObject.toString();
}