本文整理汇总了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());
}
示例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);
}
示例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);
}
示例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);
}
示例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;
}
示例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);
}
示例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);
}
示例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";
}
示例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);
}
示例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
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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;
}