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