本文整理汇总了Java中com.alibaba.fastjson.JSON.parseObject方法的典型用法代码示例。如果您正苦于以下问题:Java JSON.parseObject方法的具体用法?Java JSON.parseObject怎么用?Java JSON.parseObject使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.alibaba.fastjson.JSON
的用法示例。
在下文中一共展示了JSON.parseObject方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: parseConfig
import com.alibaba.fastjson.JSON; //导入方法依赖的package包/类
/**
* 解析参数
*
* @param args
* @return
* @throws FileNotFoundException
*/
private static Config parseConfig(String[] args) throws FileNotFoundException {
Config config = Config.of();
if (null != args && args.length > 0) {
for (int i = 0; i < args.length; i++) {
if (args[i].startsWith("--config=")) {
String[] conf = args[i].split("=");
String content = new Scanner(new File(conf[1])).useDelimiter("\\Z").next();
log.info("Probe config: \n{}", content);
config = JSON.parseObject(content, Config.class);
break;
}
}
}
return config;
}
示例2: test_concurrentHashmap
import com.alibaba.fastjson.JSON; //导入方法依赖的package包/类
public void test_concurrentHashmap() throws Exception {
OffsetSerializeWrapper wrapper = new OffsetSerializeWrapper();
wrapper.getOffsetTable().put(new MessageQueue(), new AtomicLong(123));
String text = JSON.toJSONString(wrapper);
Assert.assertEquals("{\"offsetTable\":{{\"items\":[]}:123}}", text);
OffsetSerializeWrapper wrapper2 = JSON.parseObject(text, OffsetSerializeWrapper.class);
Assert.assertEquals(1, wrapper2.getOffsetTable().size());
Iterator<Map.Entry<MessageQueue, AtomicLong>> iter = wrapper2.getOffsetTable().entrySet().iterator();
Map.Entry<MessageQueue, AtomicLong> entry = iter.next();
Assert.assertEquals(0, entry.getKey().getItems().size());
Assert.assertEquals(123L, entry.getValue().longValue());
}
示例3: test_error_9
import com.alibaba.fastjson.JSON; //导入方法依赖的package包/类
public void test_error_9() throws Exception {
JSONException error = null;
try {
String text = "{\"value\":3.2},";
JSON.parseObject(text, VO.class);
} catch (JSONException ex) {
error = ex;
}
Assert.assertNotNull(error);
}
示例4: getObject
import com.alibaba.fastjson.JSON; //导入方法依赖的package包/类
/**
* fastJson 解析Class
*
* @param json
* @param cls
* @param <T>
* @return
*/
public static <T> T getObject(String json, Class<T> cls) {
T t = null;
try {
t = JSON.parseObject(json, cls);
} catch (Exception e) {
e.printStackTrace();
}
return t;
}
示例5: test_for_issue
import com.alibaba.fastjson.JSON; //导入方法依赖的package包/类
public void test_for_issue() throws Exception {
Model model = new Model();
model._id = 1001L;
model.id = 1002L;
String json = JSON.toJSONString(model);
assertEquals("{\"_id\":1001,\"id\":1002}", json);
Model model1 = JSON.parseObject(json, Model.class);
assertEquals(json, JSON.toJSONString(model1));
}
示例6: test_deserialize_1
import com.alibaba.fastjson.JSON; //导入方法依赖的package包/类
public void test_deserialize_1() throws Exception {
String json = "{\"value\":\"\"}";
V0 vo = JSON.parseObject(json, V0.class);
Assert.assertNotNull(vo.getValue());
Assert.assertEquals("", vo.getValue().toString());
}
示例7: test_create
import com.alibaba.fastjson.JSON; //导入方法依赖的package包/类
public void test_create() throws Exception {
Entity entity = new Entity(123, "菜姐");
String text = JSON.toJSONString(entity);
Entity entity2 = JSON.parseObject(text, Entity.class);
Assert.assertEquals(entity.getId(), entity2.getId());
Assert.assertEquals(entity.getName(), entity2.getName());
}
示例8: queryPayOrder
import com.alibaba.fastjson.JSON; //导入方法依赖的package包/类
@RequestMapping(value = "/pay/query")
public String queryPayOrder(@RequestParam String jsonParam) {
_log.info("selectPayOrder << {}", jsonParam);
JSONObject retObj = new JSONObject();
retObj.put("code", "0000");
if(StringUtils.isBlank(jsonParam)) {
retObj.put("code", "0001"); // 参数错误
retObj.put("msg", "缺少参数");
return retObj.toJSONString();
}
JSONObject paramObj = JSON.parseObject(new String(MyBase64.decode(jsonParam)));
String mchId = paramObj.getString("mchId");
String payOrderId = paramObj.getString("payOrderId");
String mchOrderNo = paramObj.getString("mchOrderNo");
PayOrder payOrder;
if(StringUtils.isNotBlank(payOrderId)) {
payOrder = payOrderService.selectPayOrderByMchIdAndPayOrderId(mchId, payOrderId);
}else {
payOrder = payOrderService.selectPayOrderByMchIdAndMchOrderNo(mchId, mchOrderNo);
}
if(payOrder == null) {
retObj.put("code", "0002");
retObj.put("msg", "支付订单不存在");
return retObj.toJSONString();
}
//
boolean executeNotify = paramObj.getBooleanValue("executeNotify");
// 如果选择回调且支付状态为支付成功,则回调业务系统
if(executeNotify && payOrder.getStatus() == PayConstant.PAY_STATUS_SUCCESS) {
this.doNotify(payOrder);
}
retObj.put("result", JSON.toJSON(payOrder));
_log.info("selectPayOrder >> {}", retObj);
return retObj.toJSONString();
}
示例9: test_stack_error_3
import com.alibaba.fastjson.JSON; //导入方法依赖的package包/类
public void test_stack_error_3() throws Exception {
Exception error = null;
try {
JSON.parseObject("{\"@type\":int}", StackTraceElement.class);
} catch (JSONException ex) {
error = ex;
}
Assert.assertNotNull(error);
}
示例10: toast
import com.alibaba.fastjson.JSON; //导入方法依赖的package包/类
@JSMethod(uiThread = true)
public void toast(String param) {
String message = "";
int duration = Toast.LENGTH_SHORT;
if (!TextUtils.isEmpty(param)) {
try {
param = URLDecoder.decode(param, "utf-8");
JSONObject jsObj = JSON.parseObject(param);
message = jsObj.getString(MESSAGE);
duration = jsObj.getInteger(DURATION);
} catch (Exception e) {
WXLogUtils.e("[WXModalUIModule] alert param parse error ", e);
}
}
if (TextUtils.isEmpty(message)) {
WXLogUtils.e("[WXModalUIModule] toast param parse is null ");
return;
}
if (duration > 3) {
duration = Toast.LENGTH_LONG;
} else {
duration = Toast.LENGTH_SHORT;
}
if (toast == null) {
toast = Toast.makeText(mWXSDKInstance.getContext(), message, duration);
} else {
toast.setDuration(duration);
toast.setText(message);
}
toast.setGravity(Gravity.CENTER, 0, 0);
toast.show();
}
示例11: test_model_error_fa
import com.alibaba.fastjson.JSON; //导入方法依赖的package包/类
public void test_model_error_fa() throws Exception {
Exception error = null;
try {
JSON.parseObject("[fa", Model.class);
} catch (JSONException ex) {
error = ex;
}
Assert.assertNotNull(error);
}
示例12: perf
import com.alibaba.fastjson.JSON; //导入方法依赖的package包/类
public static void perf() {
long start = System.currentTimeMillis();
for (int i = 0; i < 1000 * 1000 * 10; ++i) {
JSON.parseObject(json, Model.class);
}
long millis = System.currentTimeMillis() - start;
System.out.println("millis : " + millis);
}
示例13: test_0
import com.alibaba.fastjson.JSON; //导入方法依赖的package包/类
public void test_0 () throws Exception {
VO vo = JSON.parseObject("{\"value\":true}", VO.class);
Assert.assertTrue(vo.value);
}
示例14: test_empty
import com.alibaba.fastjson.JSON; //导入方法依赖的package包/类
public void test_empty() throws Exception {
String text = "{\"values\":[]}";
Model model = JSON.parseObject(text, Model.class);
Assert.assertEquals(0, model.values.size());
}
示例15: test_null
import com.alibaba.fastjson.JSON; //导入方法依赖的package包/类
public void test_null() throws Exception {
Model model = JSON.parseObject("{\"v1\":null,\"v2\":null}", Model.class);
assertNotNull(model);
assertNull(model.v1);
assertNull(model.v2);
}