当前位置: 首页>>代码示例>>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;未经允许,请勿转载。