com.alibaba.fastjson.JSON.parseArray()方法的使用及代码示例

x33g5p2x  于2022-01-21 转载在 其他  
字(5.7k)|赞(0)|评价(0)|浏览(315)

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

JSON.parseArray介绍

暂无

代码示例

代码示例来源:origin: alibaba/Sentinel

public static List<DegradeRule> parseDegradeRule(String body) {
  try {
    return JSON.parseArray(body, DegradeRule.class);
  } catch (Exception e) {
    LOGGER.error("parser DegradeRule error: ", e);
    return null;
  }
}

代码示例来源:origin: hs-web/hsweb-framework

private List<Object> parseArray(String json) {
  if (!StringUtils.hasText(json)) {
    return null;
  }
  return JSON.parseArray(json);
}

代码示例来源:origin: alibaba/Sentinel

public static List<FlowRule> parseFlowRule(String body) {
  try {
    return JSON.parseArray(body, FlowRule.class);
  } catch (Exception e) {
    LOGGER.error("parser FlowRule error: ", e);
    return null;
  }
}

代码示例来源:origin: alibaba/Sentinel

public static List<SystemRule> parseSystemRule(String body) {
  try {
    return JSON.parseArray(body, SystemRule.class);
  } catch (Exception e) {
    LOGGER.info("parser SystemRule error: ", e);
    return null;
  }
}

代码示例来源:origin: weibocom/motan

@Override
public Object[] deserializeMulti(byte[] data, Class<?>[] classes) throws IOException {
   List<Object> list = JSON.parseArray(new String(data), classes);
   if (list != null) {
     return list.toArray();
   }
   return null;
}

代码示例来源:origin: mpusher/mpush

public static <T> List<T> fromJsonToList(String json, Class<T> type) {
  try {
    return JSON.parseArray(json, type);
  } catch (Exception e) {
    LOGGER.error("Jsons.fromJsonToList ex, json=" + json + ", type=" + type, e);
  }
  return null;
}

代码示例来源:origin: yanzhenjie/NoHttp

@Override
protected List<Entity> parseEntity(String responseBody) throws Throwable {
  if (!TextUtils.isEmpty(responseBody)) {
    List<Entity> entities = JSON.parseArray(responseBody, clazz);
    return entities == null ? Collections.<Entity>emptyList() : entities;
  }
  return Collections.emptyList();
}

代码示例来源:origin: hs-web/hsweb-framework

@Override
@SuppressWarnings("unchecked")
public AuthenticationBuilder role(String role) {
  return role((List) JSON.parseArray(role, SimpleRole.class));
}

代码示例来源:origin: hs-web/hsweb-framework

@Override
public <T> Optional<List<T>> asList(Class<T> t) {
  return getNativeValue()
      .map(v -> JSON.parseArray(v, t));
}

代码示例来源:origin: alibaba/Sentinel

public static List<AuthorityRule> parseAuthorityRule(String body) {
  if (StringUtil.isBlank(body)) {
    return null;
  }
  try {
    return JSON.parseArray(body, AuthorityRule.class);
  } catch (Exception e) {
    LOGGER.error("Error when parsing authority rules", e);
    return null;
  }
}

代码示例来源:origin: hs-web/hsweb-framework

default JSONArray resultAsJsonArray() {
    return JSON.parseArray(resultAsString());
  }
}

代码示例来源:origin: alibaba/Sentinel

public List<NodeVo> fetchResourceOfMachine(String ip, int port, String type) {
  String url = "http://" + ip + ":" + port + "/" + RESOURCE_URL_PATH + "?type=" + type;
  String body = httpGetContent(url);
  if (body == null) {
    return null;
  }
  try {
    return JSON.parseArray(body, NodeVo.class);
  } catch (Exception e) {
    logger.info("parse ResourceOfMachine error", e);
    return null;
  }
}

代码示例来源:origin: alibaba/Sentinel

/**
 * Parse parameter flow rules.
 *
 * @param body raw string content
 * @return parsed rule list; null if error occurs or empty content
 */
public static List<ParamFlowRule> parseParamFlowRule(String body) {
  if (StringUtil.isBlank(body)) {
    return null;
  }
  try {
    return JSON.parseArray(body, ParamFlowRule.class);
  } catch (Exception e) {
    LOGGER.error("Error when parsing parameter flow rules", e);
    return null;
  }
}

代码示例来源:origin: code4craft/webmagic

public <T> List<T> toList(Class<T> clazz) {
  if (getFirstSourceText() == null) {
    return null;
  }
  return JSON.parseArray(getFirstSourceText(), clazz);
}

代码示例来源:origin: TommyLemon/APIJSON

/**json转JSONArray
 * @param json
 * @return
 */
public static JSONArray parseArray(String json) {
  try {
    return com.alibaba.fastjson.JSON.parseArray(getCorrectJson(json, true));
  } catch (Exception e) {
    Log.i(TAG, "parseArray  catch \n" + e.getMessage());
  }
  return null;
}
/**JSONArray转实体类列表

代码示例来源:origin: TommyLemon/APIJSON

/**json转JSONArray
 * @param json
 * @return
 */
public static JSONArray parseArray(String json) {
  try {
    return com.alibaba.fastjson.JSON.parseArray(getCorrectJson(json, true));
  } catch (Exception e) {
    Log.i(TAG, "parseArray  catch \n" + e.getMessage());
  }
  return null;
}
/**JSONArray转实体类列表

代码示例来源:origin: hs-web/hsweb-framework

@Override
  public CandidateDimension parse(DimensionContext context, String jsonConfig) {
    JSONArray jsonArray;
    if (jsonConfig.startsWith("[")) {
      jsonArray = JSON.parseArray(jsonConfig);
    } else {
      JSONObject jsonObject = JSON.parseObject(jsonConfig);
      jsonArray = new JSONArray();
      jsonArray.add(jsonObject);
    }
    return parse(context, jsonArray);

  }
}

代码示例来源:origin: TommyLemon/APIJSON

/**
 * @param json
 * @param clazz
 * @return
 */
public static <T> List<T> parseArray(String json, Class<T> clazz) {
  try {
    return com.alibaba.fastjson.JSON.parseArray(getCorrectJson(json), clazz);
  } catch (Exception e) {
    Log.e(TAG, "parseArray  catch \n" + e.getMessage());
  }
  return null;
}

代码示例来源:origin: hs-web/hsweb-framework

protected JobDataMap createJobDataMap(String parameters) {
  JobDataMap map = new JobDataMap();
  if (!StringUtils.isEmpty(parameters)) {
    JSONArray jsonArray = JSON.parseArray(parameters);
    for (int i = 0; i < jsonArray.size(); i++) {
      JSONObject o = jsonArray.getJSONObject(i);
      map.put(o.getString("key"), o.get("value"));
    }
  }
  return map;
}

代码示例来源:origin: TommyLemon/APIJSON

/**json转实体类列表
 * @param json
 * @param clazz
 * @return
 */
public static <T> List<T> parseArray(String json, Class<T> clazz) {
  if (clazz == null) {
    Log.e(TAG, "parseArray  clazz == null >> return null;");
  } else {
    try {
      return com.alibaba.fastjson.JSON.parseArray(getCorrectJson(json, true), clazz);
    } catch (Exception e) {
      Log.i(TAG, "parseArray  catch \n" + e.getMessage());
    }
  }
  return null;
}

相关文章