本文整理匯總了Java中org.json.JSONObject.append方法的典型用法代碼示例。如果您正苦於以下問題:Java JSONObject.append方法的具體用法?Java JSONObject.append怎麽用?Java JSONObject.append使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.json.JSONObject
的用法示例。
在下文中一共展示了JSONObject.append方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getURLDetails
import org.json.JSONObject; //導入方法依賴的package包/類
public static JSONObject getURLDetails(String shortURL) {
JSONObject json = new JSONObject();
try {
Record record = db.readKey(Constants.URLS, shortURL);
json.append(Constants.SHORT_URL, shortURL);
json.append(Constants.LONG_URL, record.getString(Constants.LONG_URL));
json.append(Constants.HIT_COUNT, record.getLong(Constants.HIT_COUNT));
Date date = new Date(record.getLong(Constants.TIMESTAMP));
DateFormat format = new SimpleDateFormat( "MM/dd/yyyy HH:mm:ss");
json.append(Constants.TIMESTAMP, format.format(date));
} catch (Exception e) {
e.printStackTrace();
try {
json.append(Constants.MESSAGE, Constants.INVALID_SHORT_URL);
json.remove(Constants.SHORT_URL);
} catch (JSONException e1) {
e1.printStackTrace();
}
}
return json;
}
示例2: demoPushDeviceListMultiple
import org.json.JSONObject; //導入方法依賴的package包/類
protected JSONObject demoPushDeviceListMultiple() throws JSONException {
XingeClient xinge = new XingeClient(000, "secret_key");
Message message = new Message();
message.setExpireTime(86400);
message.setTitle("title");
message.setContent("content");
message.setType(Message.TYPE_NOTIFICATION);
JSONObject ret = xinge.createMultipush(message);
if (ret.getInt("ret_code") != 0)
return (ret);
else {
JSONObject result = new JSONObject();
List<String> deviceList1 = new ArrayList<String>();
deviceList1.add("joelliu1");
deviceList1.add("joelliu2");
// ...
result.append("all", xinge.pushDeviceListMultiple(ret.getJSONObject("result").getInt("push_id"), deviceList1));
List<String> deviceList2 = new ArrayList<String>();
deviceList2.add("joelliu3");
deviceList2.add("joelliu4");
// ...
result.append("all", xinge.pushDeviceListMultiple(ret.getJSONObject("result").getInt("push_id"), deviceList2));
return (result);
}
}
示例3: getURLDetails
import org.json.JSONObject; //導入方法依賴的package包/類
@GET
@Path("/details/{shortURL}")
@Produces(MediaType.APPLICATION_JSON)
public String getURLDetails(@PathParam("shortURL") String shortURL) {
JSONObject json = TinyURL.getURLDetails(shortURL);
try {
json.put(SHORT_URL, request.getServerName() + "/" + shortURL);
} catch (Exception e) {
e.printStackTrace();
try {
json.append(MESSAGE, SOMETHING_WENT_WRONG);
} catch (JSONException e1) {
e1.printStackTrace();
}
}
return json.toString();
}
示例4: setURL
import org.json.JSONObject; //導入方法依賴的package包/類
@POST
@Produces(MediaType.APPLICATION_JSON)
public String setURL(@FormParam("url") String longURL, @FormParam("captcha") String captcha) throws IOException {
JSONObject json = new JSONObject();
if(!VerifyCaptcha.verify(captcha)) return json.toString();
try {
String shortURL = TinyURL.setURL(longURL);
json.put(SHORT_URL, request.getServerName() + "/" + shortURL);
} catch (JSONException e) {
e.printStackTrace();
try {
json.append(MESSAGE, SOMETHING_WENT_WRONG);
} catch (JSONException e1) {
e1.printStackTrace();
}
}
return json.toString();
}
示例5: demoPushAccountListMultiple
import org.json.JSONObject; //導入方法依賴的package包/類
protected JSONObject demoPushAccountListMultiple() throws JSONException {
XingeClient xinge = new XingeClient(000, "secret_key");
Message message = new Message();
message.setExpireTime(86400);
message.setTitle("title");
message.setContent("content");
message.setType(Message.TYPE_NOTIFICATION);
JSONObject ret = xinge.createMultipush(message);
if (ret.getInt("ret_code") != 0)
return (ret);
else {
JSONObject result = new JSONObject();
List<String> accountList1 = new ArrayList<String>();
accountList1.add("joelliu1");
accountList1.add("joelliu2");
// ...
result.append("all", xinge.pushAccountListMultiple(ret.getJSONObject("result").getInt("push_id"), accountList1));
List<String> accountList2 = new ArrayList<String>();
accountList2.add("joelliu3");
accountList2.add("joelliu4");
// ...
result.append("all", xinge.pushAccountListMultiple(ret.getJSONObject("result").getInt("push_id"), accountList2));
return (result);
}
}