當前位置: 首頁>>代碼示例>>Java>>正文


Java JSONObject.put方法代碼示例

本文整理匯總了Java中com.alibaba.fastjson.JSONObject.put方法的典型用法代碼示例。如果您正苦於以下問題:Java JSONObject.put方法的具體用法?Java JSONObject.put怎麽用?Java JSONObject.put使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.alibaba.fastjson.JSONObject的用法示例。


在下文中一共展示了JSONObject.put方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getJSONObject

import com.alibaba.fastjson.JSONObject; //導入方法依賴的package包/類
private JSONObject getJSONObject(Cursor cursor, String[] keys) throws Exception
{
    JSONObject jsonObject = new JSONObject();
    if (keys == null || keys.length == 0)
    {
        int columnCount = cursor.getColumnCount();
        for (int i = 0; i < columnCount; i++)
        {
            jsonObject.put(cursor.getColumnName(i), TypeUtil.getObject(cursor, i));
        }
    } else
    {
        for (String string : keys)
        {
            int index = cursor.getColumnIndexOrThrow(string);
            jsonObject.put(string, TypeUtil.getObject(cursor, index));
        }
    }

    return jsonObject;
}
 
開發者ID:gzxishan,項目名稱:OftenPorter,代碼行數:22,代碼來源:SqliteHandle.java

示例2: list

import com.alibaba.fastjson.JSONObject; //導入方法依賴的package包/類
@RequestMapping("/list")
@ResponseBody
public String list(@ModelAttribute MchInfo mchInfo, Integer pageIndex, Integer pageSize) {
    PageModel pageModel = new PageModel();
    int count = mchInfoService.count(mchInfo);
    if(count <= 0) return JSON.toJSONString(pageModel);
    List<MchInfo> mchInfoList = mchInfoService.getMchInfoList((pageIndex-1)*pageSize, pageSize, mchInfo);
    if(!CollectionUtils.isEmpty(mchInfoList)) {
        JSONArray array = new JSONArray();
        for(MchInfo mi : mchInfoList) {
            JSONObject object = (JSONObject) JSONObject.toJSON(mi);
            object.put("createTime", DateUtil.date2Str(mi.getCreateTime()));
            array.add(object);
        }
        pageModel.setList(array);
    }
    pageModel.setCount(count);
    pageModel.setMsg("ok");
    pageModel.setRel(true);
    return JSON.toJSONString(pageModel);
}
 
開發者ID:ywtnhm,項目名稱:pay-xxpay-master,代碼行數:22,代碼來源:MchInfoController.java

示例3: lastdp

import com.alibaba.fastjson.JSONObject; //導入方法依賴的package包/類
@Override
public List<LastDPValue> lastdp(Collection<Timeline> timelines) throws HttpUnknowStatusException {
	Object timelinesJSON = JSON.toJSON(timelines);
	JSONObject obj = new JSONObject();
	obj.put("queries", timelinesJSON);
	String jsonString = obj.toJSONString();
	HttpResponse httpResponse = httpclient.post(HttpAPI.QUERY_LASTDP, jsonString);
	ResultResponse resultResponse = ResultResponse.simplify(httpResponse, this.httpCompress);
	HttpStatus httpStatus = resultResponse.getHttpStatus();
	switch (httpStatus) {
	case ServerSuccessNoContent:
		return null;
	case ServerSuccess:
		String content = resultResponse.getContent();
		List<LastDPValue> queryResultList = JSON.parseArray(content, LastDPValue.class);
		return queryResultList;
	case ServerNotSupport:
		throw new HttpServerNotSupportException(resultResponse);
	case ServerError:
		throw new HttpServerErrorException(resultResponse);
	default:
		throw new HttpUnknowStatusException(resultResponse);
	}
}
 
開發者ID:aliyun,項目名稱:HiTSDB-Client,代碼行數:25,代碼來源:HiTSDBClient.java

示例4: indices

import com.alibaba.fastjson.JSONObject; //導入方法依賴的package包/類
public String indices() {
	String uri = "/_cat/indices?v";
	String result = base(uri, HttpUtil.METHOD_GET,  null);
	if(!StringUtil.isEmpty(result)){
		String[] data = result.split("\n");
		if(data!=null&&data.length>1){
			List<JSONObject> list = new ArrayList<JSONObject>();
			String[] header = data[0].split("(\\s+)");
			for(int i=1;i<data.length;i++){
				String[] values = data[i].split("(\\s+)");
				JSONObject json = new JSONObject();
				for(int j=0;j<values.length;j++){
					json.put(header[j], values[j]);
				}
				list.add(json);
			}
			if(list!=null&&list.size()==1){
				return list.get(0).toJSONString();
			}else{
				return JSON.toJSONString(list);
			}
		}
	}
	return result;
}
 
開發者ID:dev-share,項目名稱:database-transform-tool,代碼行數:26,代碼來源:ElasticsearchHttpFactory.java

示例5: nodes

import com.alibaba.fastjson.JSONObject; //導入方法依賴的package包/類
public String nodes() {
	String uri = "/_cat/nodes?v";
	String result = base(uri, HttpUtil.METHOD_GET,  null);
	if(!StringUtil.isEmpty(result)){
		String[] data = result.split("\n");
		if(data!=null&&data.length>1){
			List<JSONObject> list = new ArrayList<JSONObject>();
			String[] header = data[0].split("(\\s+)");
			for(int i=1;i<data.length;i++){
				String[] values = data[i].split("(\\s+)");
				JSONObject json = new JSONObject();
				for(int j=0;j<values.length;j++){
					json.put(header[j], values[j]);
				}
				list.add(json);
			}
			if(list!=null&&list.size()==1){
				return list.get(0).toJSONString();
			}else{
				return JSON.toJSONString(list);
			}
		}
	}
	return result;
}
 
開發者ID:dev-share,項目名稱:css-elasticsearch,代碼行數:26,代碼來源:ElasticsearchHttpFactory.java

示例6: test_cast_to_Timestamp_number

import com.alibaba.fastjson.JSONObject; //導入方法依賴的package包/類
public void test_cast_to_Timestamp_number() throws Exception {
    long millis = System.currentTimeMillis();

    JSONObject json = new JSONObject();
    json.put("date", new BigDecimal(Long.toString(millis)));
    Assert.assertEquals(new java.sql.Timestamp(millis), json.getObject("date", java.sql.Timestamp.class));
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:8,代碼來源:TypeUtilsTest.java

示例7: handleRequest

import com.alibaba.fastjson.JSONObject; //導入方法依賴的package包/類
@Override
public String handleRequest(IUser user, String jsonString) {
	JSONObject jsonObject=JSONObject.parseObject(jsonString);

	String img = jsonObject.getString("img");
	String name = jsonObject.getString("name");
	UserEntity userEntity=new UserEntity();
	userEntity.setUserId(user.getIObject().getUtfString(PrefixConstant.LOGIN_NAME));
	userEntity.setAccountId(user.getIObject().getUtfString(PrefixConstant.LOGIN_NAME));
	userEntity.setLevel(1);
	userEntity.setUserName(name);
	userEntity.setHeadImg(img);

	JongoDBService manager = AppContext.getManager(JongoDBService.class);
	 UserManager.getInstance().createUser(manager.getJongo(), userEntity);

	String loginName = user.getIObject().getUtfString(PrefixConstant.LOGIN_NAME);
	String loginParms = user.getIObject().getUtfString(PrefixConstant.LOGIN_PARMS);

	AccountEntity accountEntity = AccountManager.getInstance().selectAccount(manager.getJongo(), loginName, loginParms);
	accountEntity.setUserId(userEntity.getUserId());
	AccountManager.getInstance().updateAccount(manager.getJongo(),accountEntity);
	
	JSONObject object = new JSONObject();
	object.put("state", "ok");
	object.put("name", name);
	object.put("userId", img);

	return object.toJSONString();
}
 
開發者ID:zerosoft,項目名稱:CodeBroker,代碼行數:31,代碼來源:CreateUserRequest.java

示例8: getMenus

import com.alibaba.fastjson.JSONObject; //導入方法依賴的package包/類
/**
 * 返回菜單
 * @param model
 * @param getAll 是否返回所有菜單
 * @return
 */
public JSONArray getMenus(SysMenu model,boolean getAll){
    Example example = new Example(SysMenu.class);
    Example.Criteria criteria = example.createCriteria();
    JSONArray list=new JSONArray();
    if (StringUtils.isEmpty(model.getId())) {
        criteria.andEqualTo("parentId","0");//獲取公司
    }else {
        criteria.andEqualTo("parentId",model.getId());
    }
    List<SysMenu> midList = mapper.selectByExample(example);
    if(midList!=null){
        for (SysMenu item:midList) {
            JSONObject obj=new JSONObject();
            obj.put("name",item.getName());
            obj.put("id",item.getId());
            obj.put("pId",item.getParentId());
            boolean isParent=isHaveChild(item.getId());
            obj.put("isParent",""+isParent);
            if(getAll&&isParent) {
                obj.put("children", getMenus(item,getAll));
            }
            list.add(obj);
        }
    }
    return list;
}
 
開發者ID:egojit8,項目名稱:easyweb,代碼行數:33,代碼來源:SysMenuService.java

示例9: test_dupType

import com.alibaba.fastjson.JSONObject; //導入方法依賴的package包/類
public void test_dupType() throws Exception {
    DianDianCart cart = new DianDianCart();
    cart.setId(1001);
    
    LinkedHashMap<String, JSONObject> cartMap = new LinkedHashMap<String, JSONObject>();
    
    JSONObject obj = new JSONObject();
    obj.put("id", 1001);
    obj.put(JSON.DEFAULT_TYPE_KEY, "com.alibaba.json.bvt.writeClassName.WriteDuplicateType$DianDianCart");
    cartMap.put("1001", obj);
    
    String text1 = JSON.toJSONString(cartMap, SerializerFeature.WriteClassName);
    Assert.assertEquals("{\"@type\":\"java.util.LinkedHashMap\",\"1001\":{\"@type\":\"com.alibaba.json.bvt.writeClassName.WriteDuplicateType$DianDianCart\",\"id\":1001}}", text1);
    
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:16,代碼來源:WriteDuplicateType.java

示例10: addPageInfo

import com.alibaba.fastjson.JSONObject; //導入方法依賴的package包/類
public JsonUtil addPageInfo(PageInfo<?> pageInfo){
    JSONObject page = new JSONObject();
    page.put("currentPage", Integer.valueOf(pageInfo.getPageNum()));
    page.put("pages", Integer.valueOf(pageInfo.getPages()));
    page.put("total", Long.valueOf(pageInfo.getTotal()));
    this.jsonObject.put("page",page);
    return this;
}
 
開發者ID:nyh137,項目名稱:SSMFrameBase,代碼行數:9,代碼來源:JsonUtil.java

示例11: test_4

import com.alibaba.fastjson.JSONObject; //導入方法依賴的package包/類
public void test_4() throws Exception {
    JSONObject obj = new JSONObject();
    obj.put("val", "2017-08-04 15:16:41.000000");

    Model model = obj.toJavaObject(Model.class);
    assertNotNull(model.val);
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:8,代碼來源:Issue1370.java

示例12: testGenInt

import com.alibaba.fastjson.JSONObject; //導入方法依賴的package包/類
public void testGenInt() throws Exception {
    JSONObject json = new JSONObject(true);
    for (int i = 0; i < 100; ++i) {
        json.put("f" + i, i);
    }
    String text = JSON.toJSONString(json, false);
    System.out.println(text);
    FileUtils.writeStringToFile(new File("d:/int_array_1000.json"), text);
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:10,代碼來源:GenerateTest.java

示例13: getSuccessResultJsonFormatDate

import com.alibaba.fastjson.JSONObject; //導入方法依賴的package包/類
/**
 * 格式日期後得到的返回結果,日期需要@JSONField(format="yyyy-MM-dd HH:mm:ss")進行注解
 * @param obj
 * @return
 */
public static JSONObject getSuccessResultJsonFormatDate(Object obj) {
    JSONObject resultJsonObject = getResultJson(ResultCodeEnum.SUCCESS);
    resultJsonObject.put(CODE, ResultCodeEnum.SUCCESS.getValue());
    resultJsonObject.put(MSG, ResultCodeEnum.SUCCESS.getKey());
    setData(resultJsonObject,JSONObject.toJSON(obj));
    return resultJsonObject;
}
 
開發者ID:fier-liu,項目名稱:FCat,代碼行數:13,代碼來源:JsonUtil.java

示例14: toJsonString

import com.alibaba.fastjson.JSONObject; //導入方法依賴的package包/類
public String toJsonString() {
  JSONObject jsonObject = new JSONObject();
  jsonObject.put(ITEM_KEY_CONVCERSATION_ID, conversationId);
  jsonObject.put(ITEM_KEY_UNREADCOUNT, unreadCount);
  jsonObject.put(ITEM_KEY_UNDATE_TIME, updateTime);
  return jsonObject.toJSONString();
}
 
開發者ID:linsir6,項目名稱:TripBuyer,代碼行數:8,代碼來源:LCIMConversationItem.java

示例15: updateRecordLog

import com.alibaba.fastjson.JSONObject; //導入方法依賴的package包/類
private void updateRecordLog(LogOperate operate,String sql,Object ...args){
    MySqlStatementParser mySqlStatementParser = new MySqlStatementParser(sql);
    SQLUpdateStatement sqlUpdateStatement = mySqlStatementParser.parseUpdateStatement();
    SQLTableSource tableSource = sqlUpdateStatement.getTableSource();
    Assert.notNull(tableSource,"不匹配的操作類型,日誌記錄失敗!");

    List<SQLUpdateSetItem> items = sqlUpdateStatement.getItems();
    JSONObject log = new JSONObject();
    for (int i = 0; i < items.size(); i++) {
        SQLUpdateSetItem sqlUpdateSetItem = items.get(i);
        log.put(sqlUpdateSetItem.getColumn().toString(),args[i]);
    }

    logHandler.handle(operate,sqlUpdateStatement.getTableName().getSimpleName(),sqlUpdateStatement.getTableName().getSimpleName(),log);
}
 
開發者ID:zuonima,項目名稱:sql-utils,代碼行數:16,代碼來源:LogJdbcTemplate.java


注:本文中的com.alibaba.fastjson.JSONObject.put方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。