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


Java JSON.parseObject方法代码示例

本文整理汇总了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;
}
 
开发者ID:biezhi,项目名称:probe,代码行数:23,代码来源:ProbeLuncher.java

示例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());
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:15,代码来源:ConcurrentHashMapTest.java

示例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);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:11,代码来源:JSONScannerTest_scanFieldFloat.java

示例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;
}
 
开发者ID:sundevin,项目名称:utilsLibrary,代码行数:19,代码来源:FastJsonUtils.java

示例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));
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:11,代码来源:Issue1487.java

示例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());
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:8,代码来源:StringBufferFieldTest.java

示例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());
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:9,代码来源:JSONCreatorTest.java

示例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();
}
 
开发者ID:ywtnhm,项目名称:pay-xxpay-master,代码行数:37,代码来源:PayOrderServiceController.java

示例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);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:10,代码来源:StackTraceElementDeserializerTest.java

示例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();
}
 
开发者ID:weexext,项目名称:ucar-weex-core,代码行数:35,代码来源:WXModalUIModule.java

示例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);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:10,代码来源:BooleanFieldTest_array.java

示例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);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:9,代码来源:ByteBenchmark_obj.java

示例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);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:5,代码来源:BooleanObjectFieldTest.java

示例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());
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:6,代码来源:ListStringFieldTest_dom_treeSet.java

示例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);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:7,代码来源:FloatNullTest.java


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