本文整理汇总了Java中net.sf.json.JSONObject.put方法的典型用法代码示例。如果您正苦于以下问题:Java JSONObject.put方法的具体用法?Java JSONObject.put怎么用?Java JSONObject.put使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类net.sf.json.JSONObject
的用法示例。
在下文中一共展示了JSONObject.put方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: caclucateMetrics
import net.sf.json.JSONObject; //导入方法依赖的package包/类
private static JSONObject caclucateMetrics(List<SampleResult> accumulatedValues, List<SampleResult> intervalValues, String label) {
final JSONObject res = new JSONObject();
res.put("n", accumulatedValues.size()); // total count of samples
res.put("name", label); // label
res.put("interval", 1); // not used
res.put("samplesNotCounted", 0); // not used
res.put("assertionsNotCounted", 0); // not used
res.put("failedEmbeddedResources", "[]"); // not used
res.put("failedEmbeddedResourcesSpilloverCount", 0); // not used
res.put("otherErrorsCount", 0); // not used
res.put("percentileHistogram", "[]"); // not used
res.put("percentileHistogramLatency", "[]"); // not used
res.put("percentileHistogramBytes", "[]"); // not used
res.put("empty", "[]"); // not used
res.put("summary", generateSummary(accumulatedValues)); // summary info
res.put("intervals", calculateIntervals(intervalValues)); // list of intervals
addErrors(res, accumulatedValues);
return res;
}
示例2: doPost
import net.sf.json.JSONObject; //导入方法依赖的package包/类
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
JSONObject voo = new JSONObject();
voo.put("aircraft", "A320");
voo.put("maxPax", 200);
JSONObject piloto = new JSONObject();
piloto.put("firstName", "John");
piloto.put("lastName", "Doe");
voo.put("pilot", piloto);
voo.accumulate("passenger", "George");
voo.accumulate("passenger", "Thomas");
// enviar os dados no formato JSON
PrintWriter out = response.getWriter();
response.setContentType("text/plain");
out.println(voo.toString(2));
}
示例3: test_xml
import net.sf.json.JSONObject; //导入方法依赖的package包/类
public void test_xml() throws Exception {
XMLSerializer xmlSerializer = new XMLSerializer();
JSONObject json = new JSONObject();
json.put("id", 123);
json.put("name", "jobs");
json.put("flag", true);
JSONArray items = new JSONArray();
items.add("x");
items.add(234);
items.add(false);
json.put("items", items);
String text = xmlSerializer.write(json);
System.out.println(text);
}
示例4: list
import net.sf.json.JSONObject; //导入方法依赖的package包/类
/**
* @param page
* @param rows
* @param s_user
* @param response
* @return
* @throws Exception
*/
@RequestMapping("/list")
public String list(@RequestParam(value = "page", required = false) String page, @RequestParam(value = "rows", required = false) String rows, User s_user, HttpServletResponse response) throws Exception {
Map<String, Object> map = new HashMap<String, Object>();
if (page != null && rows != null) {
PageBean pageBean = new PageBean(Integer.parseInt(page),
Integer.parseInt(rows));
map.put("start", pageBean.getStart());
map.put("size", pageBean.getPageSize());
}
map.put("userName", StringUtil.formatLike(s_user.getUserName()));
List<User> userList = userService.findUser(map);
Long total = userService.getTotalUser(map);
JSONObject result = new JSONObject();
JSONArray jsonArray = JSONArray.fromObject(userList);
result.put("rows", jsonArray);
result.put("total", total);
log.info("request: user/list , map: " + map.toString());
ResponseUtil.write(response, result);
return null;
}
示例5: extractInfo
import net.sf.json.JSONObject; //导入方法依赖的package包/类
private JSONArray extractInfo(ResultSet rs) {
JSONArray jsa = new JSONArray();
ResultSetMetaData md;
try {
md = rs.getMetaData();
int column = md.getColumnCount();
while (rs.next()) {
JSONObject jsb = new JSONObject();
for (int i = 1; i <= column; i++) {
jsb.put(md.getColumnName(i), rs.getObject(i));
}
jsa.add(jsb);
}
} catch (SQLException e) {
e.printStackTrace();
}
return jsa;
}
示例6: delete
import net.sf.json.JSONObject; //导入方法依赖的package包/类
/**
* 删除
*
* @param ids
* @param response
* @return
* @throws Exception
*/
@RequestMapping("/delete")
public String delete(@RequestParam(value = "ids") String ids,
HttpServletResponse response) throws Exception {
JSONObject result = new JSONObject();
String[] idsStr = ids.split(",");
for (int i = 0; i < idsStr.length; i++) {
storeService.delStore(idsStr[i]);
}
result.put("success", true);
ResponseUtil.write(response, result);
log.info("request: store/delete , ids: " + ids);
return null;
}
示例7: popupQrImageUpdateSubmit
import net.sf.json.JSONObject; //导入方法依赖的package包/类
/**
* 通用电脑模式,更改底部的二维码,提交保存
*/
@RequestMapping(value = "popupQrImageUpdateSubmit")
public void popupQrImageUpdateSubmit(Model model,HttpServletRequest request,HttpServletResponse response,
@RequestParam("qrImageFile") MultipartFile multipartFile) throws IOException{
JSONObject json = new JSONObject();
Site site = getSite();
if(!(multipartFile.getContentType().equals("image/pjpeg") || multipartFile.getContentType().equals("image/jpeg") || multipartFile.getContentType().equals("image/png") || multipartFile.getContentType().equals("image/gif"))){
json.put("result", "0");
json.put("info", "请传入jpg、png、gif格式的二维码图");
}else{
//格式转换
BufferedImage bufferedImage = ImageUtil.inputStreamToBufferedImage(multipartFile.getInputStream());
BufferedImage tag = ImageUtil.formatConversion(bufferedImage);
BufferedImage tag1 = ImageUtil.proportionZoom(tag, 400);
//上传
AttachmentFile.put("site/"+site.getId()+"/images/qr.jpg", ImageUtil.bufferedImageToInputStream(tag1, "jpg"));
AliyunLog.addActionLog(getSiteId(), "通用电脑模式,更改底部的二维码,提交保存");
json.put("result", "1");
}
response.setCharacterEncoding("UTF-8");
response.setContentType("application/json; charset=utf-8");
PrintWriter out = null;
try {
out = response.getWriter();
out.append(json.toString());
} catch (IOException e) {
e.printStackTrace();
} finally {
if (out != null) {
out.close();
}
}
}
示例8: testFromJSON
import net.sf.json.JSONObject; //导入方法依赖的package包/类
@org.junit.Test
public void testFromJSON() throws Exception {
StatusNotifierCallbackTest.StatusNotifierCallbackImpl notifier = new StatusNotifierCallbackTest.StatusNotifierCallbackImpl();
BlazeMeterHttpUtilsEmul emul = new BlazeMeterHttpUtilsEmul(notifier, "test_address", "test_data_address", new BlazeMeterReport());
JSONObject object = new JSONObject();
object.put("id", "projectId");
object.put("name", "projectName");
Project project = Project.fromJSON(emul, object);
assertEquals("projectId", project.getId());
assertEquals("projectName", project.getName());
}
示例9: getCategories
import net.sf.json.JSONObject; //导入方法依赖的package包/类
public ArrayList<String> getCategories(){
ArrayList<String> categories=new ArrayList<String>();
JSONObject r=new JSONObject();
//构造一个请求表单
r.put("vfwebqq",credential.getVfWebQQ());
//这里用到了hash
r.put("hash", credential.getHash());
//访问获取好友列表的链接,取出分组信息
JSONArray result=JSONObject.fromObject(JSONObject.fromObject(utils.post(URL.URL_GET_FRIEND_LIST,new PostParameter[]{new PostParameter("r",r.toString())},new HttpHeader[]{URL.URL_REFERER,credential.getCookie()}).getContent("UTF-8")).getJSONObject("result")).getJSONArray("categories");
//取出分组的名称
for(int i=0;i<result.size();i++){
categories.add(JSONObject.fromObject(result.get(i)).getString("name"));
}
return categories;
}
示例10: setUp
import net.sf.json.JSONObject; //导入方法依赖的package包/类
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
jobConfigurationService = new JobConfigurationService();
formData = new JSONObject();
formData.put("projectKey", "TestKey");
}
示例11: setUp
import net.sf.json.JSONObject; //导入方法依赖的package包/类
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
globalConfigurationService = new GlobalConfigurationService();
spyGlobalConfigurationService = spy(globalConfigurationService);
listOfGlobalConfigData = new ArrayList<>();
jsonObjectNotNull = new JSONObject();
jsonObjectNotNull.put("name", "Sonar");
jsonObjectNotNull.put("url", "http://localhost:9000");
jsonObjectNotNull.put("account", "admin");
jsonObjectNotNull.put("pass", "admin");
}
示例12: save
import net.sf.json.JSONObject; //导入方法依赖的package包/类
/**
* 保存或修改
*
* @param store
* @param response
* @return
* @throws Exception
*/
@RequestMapping("/save")
public String save(Store store, HttpServletResponse response)
throws Exception {
int resultTotal = 0;
Map<String, Object> map = new HashMap<String, Object>();
map.put("number", store.getNumber());
JSONObject result = new JSONObject();
if (storeService.findStores(map).size() > 0
|| Integer.valueOf(store.getLevel()) < 1) {
result.put("success", false);
ResponseUtil.write(response, result);
} else {
if (store.getId() == null) {
resultTotal = storeService.insertStore(store);
} else {
resultTotal = storeService.updStore(store);
}
if (resultTotal > 0) {
result.put("success", true);
} else {
result.put("success", false);
}
ResponseUtil.write(response, result);
}
log.info("request: store/save , " + store.toString());
return null;
}
示例13: list
import net.sf.json.JSONObject; //导入方法依赖的package包/类
/**
* 查找相应的数据集合
*
* @param page
* @param rows
* @param article
* @param response
* @return
* @throws Exception
*/
@RequestMapping("/list")
public String list(
@RequestParam(value = "page", required = false) String page,
@RequestParam(value = "rows", required = false) String rows,
Article article, HttpServletResponse response) throws Exception {
Map<String, Object> map = new HashMap<String, Object>();
if (page != null && rows != null) {
PageBean pageBean = new PageBean(Integer.parseInt(page),
Integer.parseInt(rows));
map.put("start", pageBean.getStart());
map.put("size", pageBean.getPageSize());
}
if (article != null) {
map.put("articleTitle",
StringUtil.formatLike(article.getArticleTitle()));
}
List<Article> articleList = articleService.findArticle(map);
Long total = articleService.getTotalArticle(map);
JSONObject result = new JSONObject();
JSONArray jsonArray = JSONArray.fromObject(articleList);
result.put("rows", jsonArray);
result.put("total", total);
ResponseUtil.write(response, result);
log.info("request: article/list , map: " + map.toString());
return null;
}
示例14: testFlow
import net.sf.json.JSONObject; //导入方法依赖的package包/类
@org.junit.Test
public void testFlow() throws Exception {
StatusNotifierCallbackTest.StatusNotifierCallbackImpl notifier = new StatusNotifierCallbackTest.StatusNotifierCallbackImpl();
BlazeMeterReport report = new BlazeMeterReport();
BlazeMeterHttpUtilsEmul emul = new BlazeMeterHttpUtilsEmul(notifier, "test_address", "test_data_address", report);
User user = new User(emul);
emul.addEmul(new JSONObject());
user.ping();
JSONObject acc = new JSONObject();
acc.put("id", "accountId");
acc.put("name", "accountName");
JSONArray result = new JSONArray();
result.add(acc);
result.add(acc);
JSONObject response = new JSONObject();
response.put("result", result);
emul.addEmul(response);
List<Account> accounts = user.getAccounts();
assertEquals(2, accounts.size());
for (Account account : accounts) {
assertEquals("accountId", account.getId());
assertEquals("accountName", account.getName());
}
}
示例15: testFromJSON
import net.sf.json.JSONObject; //导入方法依赖的package包/类
@org.junit.Test
public void testFromJSON() throws Exception {
StatusNotifierCallbackTest.StatusNotifierCallbackImpl notifier = new StatusNotifierCallbackTest.StatusNotifierCallbackImpl();
BlazeMeterHttpUtilsEmul emul = new BlazeMeterHttpUtilsEmul(notifier, "test_address", "test_data_address", new BlazeMeterReport());
JSONObject object = new JSONObject();
object.put("id", "workspaceId");
object.put("name", "workspaceName");
Workspace workspace = Workspace.fromJSON(emul, object);
assertEquals("workspaceId", workspace.getId());
assertEquals("workspaceName", workspace.getName());
}