当前位置: 首页>>代码示例>>Java>>正文


Java JSONObject.toJavaObject方法代码示例

本文整理汇总了Java中com.alibaba.fastjson.JSONObject.toJavaObject方法的典型用法代码示例。如果您正苦于以下问题:Java JSONObject.toJavaObject方法的具体用法?Java JSONObject.toJavaObject怎么用?Java JSONObject.toJavaObject使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.alibaba.fastjson.JSONObject的用法示例。


在下文中一共展示了JSONObject.toJavaObject方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: remove

import com.alibaba.fastjson.JSONObject; //导入方法依赖的package包/类
@Override
public ResourceItem remove(String queueID, String key) {
    if (!lockQueue(queueID)) {
        return null;
    }
    Jedis jedis = jedisPool.getResource();
    try {
        String dataJson = jedis.hget(makeDataKey(queueID), key);
        if (isNil(dataJson)) {
            return null;
        } else {
            jedis.hdel(makeDataKey(queueID), key);
            //lrem很消耗资源,尽量减少该命令操作
            jedis.lrem(makePoolQueueKey(queueID), 1, key);
        }
        return JSONObject.toJavaObject(JSON.parseObject(dataJson), ResourceItem.class);
    } finally {
        IOUtils.closeQuietly(jedis);
        unLockQueue(queueID);
    }
}
 
开发者ID:virjar,项目名称:vscrawler,代码行数:22,代码来源:JedisQueueStore.java

示例2: test_for_issue

import com.alibaba.fastjson.JSONObject; //导入方法依赖的package包/类
public void test_for_issue() throws Exception {
    String json = "{\"c\":\"c\"}";
    TestBean tb1 = JSON.parseObject(json, TestBean.class);
    assertEquals('c', tb1.getC());

    TestBean2 tb2 = JSON.parseObject(json, TestBean2.class);
    assertEquals('c', tb2.getC().charValue());

    String json2 = JSON.toJSONString(tb2);
    JSONObject jo = JSON.parseObject(json2);

    TestBean tb12 = jo.toJavaObject(TestBean.class);
    assertEquals('c', tb12.getC());

    TestBean2 tb22 = jo.toJavaObject(TestBean2.class);
    assertEquals('c', tb22.getC().charValue());
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:18,代码来源:Issue1226.java

示例3: getFrequencyMap

import com.alibaba.fastjson.JSONObject; //导入方法依赖的package包/类
public Map<String, Frequency> getFrequencyMap() {
    if (null == frequencyMap) {
        synchronized (this) {
            if (null == frequencyMap) {
                if (StringUtils.isEmpty(frequencyInfo)) {
                    frequencyMap = Collections.emptyMap();
                } else {
                    frequencyMap = new HashMap<>(1 << 4);
                    JSONArray array = JSONObject.parseArray(frequencyInfo);
                    for (Object object : array) {
                        JSONObject o = (JSONObject) object;
                        Frequency frequency = JSONObject.toJavaObject(o, Frequency.class);
                        StringBuilder sBuilder = new StringBuilder()
                                .append(frequency.getPath()).append(KEY_SEPERATOR)
                                .append(frequency.getVersion());
                        frequencyMap.put(sBuilder.toString(), frequency);
                    }
                }
            }
        }
    }
    return frequencyMap;
}
 
开发者ID:wxz1211,项目名称:dooo,代码行数:24,代码来源:AppInfo.java

示例4: getMessageBlock

import com.alibaba.fastjson.JSONObject; //导入方法依赖的package包/类
/**
 * 解析MessageBlock
 * @param packet
 * @return
 * @throws Exception
 */
public MessageBlock getMessageBlock(DatagramPacket packet) throws UnsupportedEncodingException{
	
	
	String blockJson = new String(packet.getData(), 0, packet.getLength(), code);
	
	JSONObject messageBlockJsonO = new JSONObject();
	try {
		messageBlockJsonO = JSONObject.parseObject(blockJson);
	} catch (JSONException e) {
		//可能是重复或者错误的包
		return null;
	}
	
	MessageBlock msgBlock = JSONObject.toJavaObject(messageBlockJsonO, MessageBlock.class);
	msgBlock.setSender(packet.getAddress().toString());
	return msgBlock;
	
}
 
开发者ID:lmd,项目名称:multicast,代码行数:25,代码来源:TiandeMulticastMessageManager.java

示例5: loadRunningScheduleServers

import com.alibaba.fastjson.JSONObject; //导入方法依赖的package包/类
public static List<ScheduleServer> loadRunningScheduleServers(ZkClient zkClient,String workerType) throws Exception {
    String zkPath = "/"+Constants.SAF_WORKER_ROOT+"/"+ workerType +"/"+Constants.SAF_WORKER_SERVER;
    List<String> serverIDs = loadScheduleServerIds(zkClient, workerType);
    if ( serverIDs != null ){
        List<ScheduleServer> scheduleServers = new ArrayList<ScheduleServer>();
        for( String serverID : serverIDs ){
            byte[] value = zkClient.readData(zkPath+"/"+serverID,true);
            if ( value != null ){
                ScheduleServer server = JSONObject.toJavaObject(JSONObject.parseObject(new String(value)),ScheduleServer.class);
                if ( server.isStart() ){
                    scheduleServers.add(server);
                }
            }
        }
        return scheduleServers;
    }
    return null;
}
 
开发者ID:tiglabs,项目名称:jsf-core,代码行数:19,代码来源:WorkerUtil.java

示例6: poll

import com.alibaba.fastjson.JSONObject; //导入方法依赖的package包/类
@Override
public ResourceItem poll(String queueID) {
    if (!lockQueue(queueID)) {
        return null;
    }
    Jedis jedis = jedisPool.getResource();
    try {
        String firstResourceKey = jedis.lpop(makePoolQueueKey(queueID));
        if (isNil(firstResourceKey)) {
            return null;
        }
        String dataJson = jedis.hget(makeDataKey(queueID), firstResourceKey);
        if (isNil(dataJson)) {
            throw new IllegalStateException("this is no meta data for key queue :" + queueID + " ,for resourceKey :" + firstResourceKey);
        }
        jedis.hdel(makeDataKey(queueID), firstResourceKey);
        return JSONObject.toJavaObject(JSON.parseObject(dataJson), ResourceItem.class);
    } finally {
        IOUtils.closeQuietly(jedis);
        unLockQueue(queueID);
    }
}
 
开发者ID:virjar,项目名称:vscrawler,代码行数:23,代码来源:JedisQueueStore.java

示例7: parse

import com.alibaba.fastjson.JSONObject; //导入方法依赖的package包/类
public static BaofooCheckResp parse(String retStr) {
	if (retStr != null) {
		JSONObject json = new JSONObject();
		String[] arr = retStr.split("&");
		for (String string : arr) {
			String[] keyValue = string.split("=", 2);
			String key = keyValue[0];
			String value = null;
			if (keyValue.length < 2) {
				value = "";
			} else {
				value = keyValue[1];
			}				
			json.put(key, value);
		}
		return json.toJavaObject(BaofooCheckResp.class);
	}
	return new BaofooCheckResp();
}
 
开发者ID:yi-jun,项目名称:aaden-pay,代码行数:20,代码来源:BaofooCheckResp.java

示例8: loadScheduleServers

import com.alibaba.fastjson.JSONObject; //导入方法依赖的package包/类
/**
 * 获取指定workerType下的ScheduleServer对象
 *
 * @param zkClient
 * @param workerType
 * @return
 * @throws Exception
 */
public static List<ScheduleServer> loadScheduleServers(ZkClient zkClient,String workerType) throws Exception {
    String zkPath = "/"+Constants.SAF_WORKER_ROOT+"/"+ workerType +"/"+Constants.SAF_WORKER_SERVER;
    List<String> serverIDs = loadScheduleServerIds(zkClient, workerType);
    if ( serverIDs != null ){
        List<ScheduleServer> scheduleServers = new ArrayList<ScheduleServer>();
        for( String serverID : serverIDs ){
            byte[] value = zkClient.readData(zkPath+"/"+serverID,true);
            if ( value != null ){
                ScheduleServer server = JSONObject.toJavaObject(JSONObject.parseObject(new String(value)),ScheduleServer.class);
                scheduleServers.add(server);
            }
        }
        return scheduleServers;
    }
    return null;
}
 
开发者ID:tiglabs,项目名称:jsf-core,代码行数:25,代码来源:WorkerUtil.java

示例9: test_local_str

import com.alibaba.fastjson.JSONObject; //导入方法依赖的package包/类
public void test_local_str() throws Exception {
    Model model = new Model();
    model.locale = Locale.CHINA;

    String json = JSON.toJSONString(model);

    JSONObject jsonObject = JSON.parseObject(json);
    jsonObject.toJavaObject(Model.class);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:10,代码来源:LocaleFieldTest.java

示例10: test_local_obj

import com.alibaba.fastjson.JSONObject; //导入方法依赖的package包/类
public void test_local_obj() throws Exception {
    String json = "{\"locale\":{\"displayCountry\":\"China\",\"displayVariant\":\"\",\"displayLanguage\":\"Chinese\",\"language\":\"zh\",\"displayName\":\"Chinese (China)\",\"variant\":\"\",\"ISO3Language\":\"zho\",\"ISO3Country\":\"CHN\",\"country\":\"CN\"}}";

    JSONObject jsonObject = JSON.parseObject(json);
    Model model2 = jsonObject.toJavaObject(Model.class);
    assertEquals("CN", model2.locale.getCountry());
    assertEquals("zh", model2.locale.getLanguage());
    assertEquals(Locale.CHINA.getDisplayCountry(), model2.locale.getDisplayCountry());
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:10,代码来源:LocaleFieldTest.java

示例11: getTiandeMulticastMessage

import com.alibaba.fastjson.JSONObject; //导入方法依赖的package包/类
/**
 * 拼装还原消息
 * @param msgBlockList
 * @return
 */
public TiandeMulticastMessage getTiandeMulticastMessage(List<MessageBlock> msgBlockList){
	/* 检查 msgBlockList 是否正确 */
	if(!veryBlockList(msgBlockList)){
		throw new TiandeMultiCastException("Message block List is failed!");
	}
	
	/* 还原消息体 TiandeMulticastMessage */
	Map<Integer, String> bodyMap = new HashMap<Integer, String>();
	for(int i = 0; i < msgBlockList.size(); i++){
		MessageBlock block = msgBlockList.get(i);
		bodyMap.put(block.getIndex(), block.getBody());//保存每块的body
	}
	
	//拼接body
	StringBuilder msgSB = new StringBuilder();
	for(int index = 0; index < msgBlockList.size(); index++){
		String body = bodyMap.get(index);
		msgSB.append(body);
	}
	
	//base64解码
	String msgBase64 = msgSB.toString();
	
	TiandeMulticastMessage tiandeMulticastMessage = JSONObject.toJavaObject(JSONObject.parseObject(Base64.decode(msgBase64)), TiandeMulticastMessage.class);
	return tiandeMulticastMessage;
}
 
开发者ID:lmd,项目名称:multicast,代码行数:32,代码来源:TiandeMulticastMessageManager.java

示例12: test_2

import com.alibaba.fastjson.JSONObject; //导入方法依赖的package包/类
public void test_2() throws Exception {
    JSONObject obj = new JSONObject();
    obj.put("val", "2017-08-04 15:16:41.00");

    Model model = obj.toJavaObject(Model.class);
    assertNotNull(model.val);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:8,代码来源:Issue1370.java

示例13: test_3

import com.alibaba.fastjson.JSONObject; //导入方法依赖的package包/类
public void test_3() throws Exception {
    JSONObject obj = new JSONObject();
    obj.put("val", "2017-08-04 15:16:41.000");

    Model model = obj.toJavaObject(Model.class);
    assertNotNull(model.val);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:8,代码来源:Issue1370.java

示例14: dealResult

import com.alibaba.fastjson.JSONObject; //导入方法依赖的package包/类
@Override
public Object dealResult(ServiceResponse serviceResponse){
    if (!"0".equals(serviceResponse.getErrorCode())) {
        return null;
    }
    return JSONObject.toJavaObject(serviceResponse.getResult(), TransactionHistory.class);
}
 
开发者ID:bubicn,项目名称:bubichain-sdk-java,代码行数:8,代码来源:GetTransactionHistoryResponse.java

示例15: getSessionUser

import com.alibaba.fastjson.JSONObject; //导入方法依赖的package包/类
public SessionUser getSessionUser() {
    if (this.getData() == null || this.getData().get("user") == null) {
        return null;
    }
    JSONObject jsonObject = (JSONObject) this.getData().get("user");
    return JSONObject.toJavaObject(jsonObject, SessionUser.class);
}
 
开发者ID:ismartx,项目名称:fast,代码行数:8,代码来源:ApiRequest.java


注:本文中的com.alibaba.fastjson.JSONObject.toJavaObject方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。