leap.lang.json.JSON.decodeArray()方法的使用及代码示例

x33g5p2x  于2022-01-22 转载在 其他  
字(1.8k)|赞(0)|评价(0)|浏览(188)

本文整理了Java中leap.lang.json.JSON.decodeArray()方法的一些代码示例,展示了JSON.decodeArray()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JSON.decodeArray()方法的具体详情如下:
包路径:leap.lang.json.JSON
类名称:JSON
方法名:decodeArray

JSON.decodeArray介绍

[英]Parse the json string and returns the the array.
[中]解析json字符串并返回数组的值。

代码示例

代码示例来源:origin: org.leapframework/leap-lang

/**
 * Parse the json string and converts the raw value to the target type
 * @since 0.5.0b
 */
public static <T> List<T> decodeList(String json, Class<? extends T> valueType){
  T[] obj = decodeArray(json,valueType);
  return New.arrayList(obj);
}

代码示例来源:origin: org.leapframework/leap-webunit

/**
 * Parse the response content as json and decodes to array.
 */
default <T> T[] decodeJsonArray(Class<T> componentType) {
  return JSON.decodeArray(getContent(), componentType);
}

代码示例来源:origin: org.leapframework/leap-webapi

Type[]            actualTypes = pType.getActualTypeArguments();
if (rawType.isAssignableFrom(List.class)) {
  Object[] arr = JSON.decodeArray(jsonStr, (Class<?>) actualTypes[0]);
  T        val = (T) Arrays.stream(arr).collect(Collectors.toList());
  return val;

代码示例来源:origin: org.leapframework/leap-db

protected GenericDbDriver[] loadDrivers() {
    String configFile = this.getClass().getSimpleName() + ".driver.json";
        
    Resource r = Resources.getResource(this.getClass(),configFile);
    
    if(!r.exists()){
      return EMPTY_DRIVES;
    }
    
    try {
      String keyPrefix = I18N.getLocalizedKeyPrefix(this) + ".drivers";
      
      try(Reader reader = r.getInputStreamReader()){
        GenericDbDriver[] drivers = JSON.decodeArray(reader, GenericDbDriver.class);
        
        for(GenericDbDriver driver : drivers){
          I18N.localize(messageSource, driver, keyPrefix + "." + driver.getName());
        }
        
        return drivers;
      }
    } catch (IOException e) {
      throw new NestedIOException("Error reading driver config file '" + r.getDescription() + "', " + e.getMessage(), e);
    }
  }
}

相关文章