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


Java JSONObject.getObject方法代碼示例

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


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

示例1: test_for_issue

import com.alibaba.fastjson.JSONObject; //導入方法依賴的package包/類
public void test_for_issue() throws Exception {
    JSONObject jsonObject = new JSONObject();

    JSONArray jsonArray = new JSONArray();
    jsonArray.add(new Model());
    jsonObject.put("models", jsonArray);

    List list = jsonObject.getObject("models", new TypeReference<List<Model>>(){});

    assertEquals(1, list.size());
    assertEquals(Model.class, list.get(0).getClass());
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:13,代碼來源:Issue969.java

示例2: exports

import com.alibaba.fastjson.JSONObject; //導入方法依賴的package包/類
public void exports(JSONObject font, Double splitAtX, Double splitAtY, Double err) {
	font.put("CFF_", null);
	JSONObject glyf = font.getJSONObject("glyf");
	for (String k : glyf.keySet()) {
		JSONObject g = glyf.getJSONObject(k);
		Contour[][] contours = g.getObject("contours", Contour[][].class);
		if (contours != null) {
			contours = c2qContours(contours, splitAtX, splitAtY, err);
		}
		g.put("contours", contours);
		g.put("stemH", null);
		g.put("stemV", null);
		g.put("hintMasks", null);
		g.put("contourMasks", null);
	}
	JSONObject maxp = font.getJSONObject("maxp");
	maxp.put("version", 1.0);
}
 
開發者ID:icaoweiwei,項目名稱:otf2ttf,代碼行數:19,代碼來源:CTQ.java

示例3: test_toJavaObject

import com.alibaba.fastjson.JSONObject; //導入方法依賴的package包/類
public void test_toJavaObject() throws Exception {
    JSONObject obj = new JSONObject();
    obj.put("d1", new Date());
    obj.put("d2", System.currentTimeMillis());
    obj.put("d3", GregorianCalendar.getInstance());
    obj.put("d4", "2012-12-22");
    obj.put("d5", "2012-12-22 12:11:11");
    obj.put("d6", "2012-12-22 12:11:11.234");
    
    obj.getObject("d1", Calendar.class);
    obj.getObject("d2", Calendar.class);
    obj.getObject("d3", Calendar.class);
    obj.getObject("d4", Calendar.class);
    obj.getObject("d5", Calendar.class);
    obj.getObject("d6", Calendar.class);

    obj.getObject("d1", GregorianCalendar.class);
    obj.getObject("d2", GregorianCalendar.class);
    obj.getObject("d3", GregorianCalendar.class);
    obj.getObject("d4", GregorianCalendar.class);
    obj.getObject("d5", GregorianCalendar.class);
    obj.getObject("d6", GregorianCalendar.class);
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:24,代碼來源:Bug_for_cnhans.java

示例4: test_for_issue_179

import com.alibaba.fastjson.JSONObject; //導入方法依賴的package包/類
public void test_for_issue_179() throws Exception {
    Student student = new Student();
    School school = new School();
    school.setStudent(student);
    student.setSchool(school);

    // String schoolJSONString = JSON.toJSONString(school);
    // System.out.println(schoolJSONString);
    //
    // School fromJSONSchool = JSON.parseObject(schoolJSONString,
    // School.class);
    //
    // System.out.println(JSON.toJSONString(fromJSONSchool));

    JSONObject object = new JSONObject();
    object.put("school", school);

    String jsonString = JSON.toJSONString(object);
    System.out.println(jsonString);

    JSONObject object2 = (JSONObject) JSON.parseObject(jsonString, JSONObject.class);
    System.out.println(JSON.toJSONString(object2));

    School school2 = object2.getObject("school", School.class);
    System.out.println(school2);
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:27,代碼來源:Issue179.java

示例5: parserResponse

import com.alibaba.fastjson.JSONObject; //導入方法依賴的package包/類
public RESPONSE parserResponse(String responseContent) throws Exception {
    JSONObject _result = JSON.parseObject(responseContent);
    String _sign = _result.getString(IAliPay.Const.SIGN);
    RESPONSE _data = _result.getObject(__methodName, __class);
    if (!StringUtils.equals(_data.getCode(), "10000")) {
        if (_LOG.isDebugEnabled()) {
            _LOG.debug("ResponseContent: " + responseContent);
        }
        if (StringUtils.isNotBlank(_data.getSubCode()) && AliPayException.__ERRORS.containsKey(_data.getSubCode())) {
            throw new AliPayException(_data.getSubCode(), _data.getSubMsg());
        } else {
            throw new AliPayException(_data.getCode(), _data.getMsg());
        }
    } else {
        _data.setSign(_sign);
    }
    return _data;
}
 
開發者ID:suninformation,項目名稱:ymate-payment-v2,代碼行數:19,代碼來源:AliPayBaseResponseParser.java

示例6: test_cast_to_SqlDate_error

import com.alibaba.fastjson.JSONObject; //導入方法依賴的package包/類
public void test_cast_to_SqlDate_error() throws Exception {
    JSONObject json = new JSONObject();
    json.put("date", 0);

    JSONException error = null;
    try {
        json.getObject("date", java.sql.Date.class);
    } catch (JSONException e) {
        error = e;
    }
    Assert.assertNotNull(error);
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:13,代碼來源:TypeUtilsTest.java

示例7: test_cast_ab_error

import com.alibaba.fastjson.JSONObject; //導入方法依賴的package包/類
public void test_cast_ab_error() throws Exception {
    A a = new A();

    JSONObject json = new JSONObject();
    json.put("value", a);

    JSONException error = null;
    try {
        json.getObject("value", B.class);
    } catch (JSONException e) {
        error = e;
    }
    Assert.assertNotNull(error);
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:15,代碼來源:TypeUtilsTest.java

示例8: test_for_issue_1

import com.alibaba.fastjson.JSONObject; //導入方法依賴的package包/類
public void test_for_issue_1() throws Exception {
    JSON.DEFFAULT_DATE_FORMAT = "yyyyMMddHHmmssSSSZ";

    String json = "{\"value\":\"20180131022733000-0800\"}";
    JSONObject object = JSON.parseObject(json);
    object.getObject("value", Date.class);

    JSON.DEFFAULT_DATE_FORMAT = "yyyy-MM-dd HH:mm:ss";
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:10,代碼來源:Issue_for_zuojian.java

示例9: test_for_issue

import com.alibaba.fastjson.JSONObject; //導入方法依賴的package包/類
public void test_for_issue() throws Exception {
    long currentMillis = System.currentTimeMillis();
    TimestampBean bean = new TimestampBean();
    bean.setTimestamp(new Timestamp(currentMillis));
    String timestampJson = JSON.toJSONString(bean);

    // 這裏能轉換成功
    TimestampBean beanOfJSON = JSON.parseObject(timestampJson, TimestampBean.class);

    // 這裏拋異常 java.lang.NumberFormatException
    JSONObject jsonObject = JSON.parseObject(timestampJson);
    Timestamp timestamp2 = jsonObject.getObject("timestamp", Timestamp.class);
    assertEquals(currentMillis/1000, timestamp2.getTime() / 1000);
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:15,代碼來源:Issue1063.java

示例10: test_checkObject

import com.alibaba.fastjson.JSONObject; //導入方法依賴的package包/類
public void test_checkObject() {
    Art origin = makeOrigin();
    JSONObject articleObj = (JSONObject) JSON.toJSON(origin);

    JSONObject dataObj = new JSONObject();
    dataObj.put("art", articleObj);

    Art other = dataObj.getObject("art", Art.class);// return null;
    assertSame(origin, other); // test failed
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:11,代碼來源:Issue955.java

示例11: test_for_issue

import com.alibaba.fastjson.JSONObject; //導入方法依賴的package包/類
public void test_for_issue() throws Exception {
    String text = "{\"ckid\":\"81a5953835310708e414057adb45e826\",\"rcToken\":\"E+jkQCWSwop+JICPBHc+fxMYeExTx2NTDGZCJ8gIPg7NbMLNvfmZBPU2dR5uxpRRe+zPnOIaCATpHcSa6q+k39HGjNFFDRt9PNlEJokpxhTw9gYJ/WKoSlVR/4ibjIgjvVHxS2lNLS4=\",\"userInfo\":{\"openid\":\"oEH-vt-7mGHOQets-XbE1c3DKpVc\",\"nickname\":\"Pietro\",\"sex\":1,\"language\":\"zh_CN\",\"city\":\"\",\"province\":\"Beijing\",\"country\":\"CN\",\"headimgurl\":\"http://wx.qlogo.cn/mmopen/kox8ma2sryApONj7kInbic4iaCZD8tXL4sqe7k3wROLpb2uCZhOiceAbL69ANeXSMu9zf7hibmt3Y0Ed4A6zIt9ibnPaiciauLZn57c/0\",\"privilege\":[],\"unionid\":\"oq9QRtyW-kb6R_7289hIycrOfnyc\"},\"isNewUser\":false}";

    Root root = JSON.parseObject(text, Root.class);
    assertEquals("oq9QRtyW-kb6R_7289hIycrOfnyc", root.userInfo.unionId);

    JSONObject jsonObject = JSON.parseObject(text);
    WechatUserInfo wechatUserInfo = jsonObject.getObject("userInfo", WechatUserInfo.class);

    assertEquals("oq9QRtyW-kb6R_7289hIycrOfnyc", wechatUserInfo.unionId);
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:12,代碼來源:Bug_for_issue_807.java

示例12: test_for_xiayucai2012

import com.alibaba.fastjson.JSONObject; //導入方法依賴的package包/類
public void test_for_xiayucai2012() throws Exception {
    String text = "{\"date\":\"0000-00-00 00:00:00\"}";
    JSONObject json = JSON.parseObject(text);
    Date date = json.getObject("date", Date.class);
    
    SimpleDateFormat dateFormat = new SimpleDateFormat(JSON.DEFFAULT_DATE_FORMAT, JSON.defaultLocale);
    dateFormat.setTimeZone(JSON.defaultTimeZone);
    
    Assert.assertEquals(dateFormat.parse(json.getString("date")), date);
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:11,代碼來源:Bug_for_xiayucai2012.java

示例13: test_for_issue_177

import com.alibaba.fastjson.JSONObject; //導入方法依賴的package包/類
public void test_for_issue_177() throws Exception {
    JSONObject jsonObject = new JSONObject();
    jsonObject.put("data", new byte[20]);

    String jsonString = JSON.toJSONString(jsonObject);
    JSONObject parseObject = JSON.parseObject(jsonString);

    byte[] bytes = parseObject.getBytes("data");

    byte[] bs = parseObject.getObject("data", byte[].class);
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:12,代碼來源:Issue177.java

示例14: test_for_issue

import com.alibaba.fastjson.JSONObject; //導入方法依賴的package包/類
public void test_for_issue() throws Exception {
    long currentMillis = System.currentTimeMillis();
    TimestampBean bean = new TimestampBean();
    bean.setTimestamp(new Date(currentMillis));
    String timestampJson = JSON.toJSONString(bean);

    // 這裏能轉換成功
    TimestampBean beanOfJSON = JSON.parseObject(timestampJson, TimestampBean.class);

    // 這裏拋異常 java.lang.NumberFormatException
    JSONObject jsonObject = JSON.parseObject(timestampJson);
    Timestamp timestamp2 = jsonObject.getObject("timestamp", Timestamp.class);
    assertEquals(currentMillis/1000, timestamp2.getTime() / 1000);
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:15,代碼來源:Issue1063_date.java

示例15: getMenu

import com.alibaba.fastjson.JSONObject; //導入方法依賴的package包/類
/**
 * 查詢菜單
 */
public Menu getMenu() {
	logger.info("查詢菜單");
	String resultStr = HttpUtils.get(MENU_GET_GET_URL + this.accessToken);
	try {
		WeChatUtil.isSuccess(resultStr);
	} catch (WeChatException e) {
		e.printStackTrace();
		return null;
	}
	JSONObject menuObject = JSONObject.parseObject(resultStr);
	Menu menu = menuObject.getObject("menu", Menu.class);
	return menu;
}
 
開發者ID:funtl,項目名稱:framework,代碼行數:17,代碼來源:MenuManager.java


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