本文整理了Java中com.alibaba.fastjson.JSONArray.parseArray()
方法的一些代码示例,展示了JSONArray.parseArray()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JSONArray.parseArray()
方法的具体详情如下:
包路径:com.alibaba.fastjson.JSONArray
类名称:JSONArray
方法名:parseArray
暂无
代码示例来源:origin: alibaba/Sentinel
@Override
public CommandResponse<String> handle(CommandRequest request) {
String data = request.getParam("data");
if (StringUtil.isBlank(data)) {
return CommandResponse.ofFailure(new IllegalArgumentException("Bad data"));
}
try {
data = URLDecoder.decode(data, "utf-8");
} catch (Exception e) {
RecordLog.info("Decode rule data error", e);
return CommandResponse.ofFailure(e, "decode rule data error");
}
RecordLog.info(String.format("[API Server] Receiving rule change (type:parameter flow rule): %s", data));
String result = SUCCESS_MSG;
List<ParamFlowRule> flowRules = JSONArray.parseArray(data, ParamFlowRule.class);
ParamFlowRuleManager.loadRules(flowRules);
if (!writeToDataSource(paramFlowWds, flowRules)) {
result = WRITE_DS_FAILURE_MSG;
}
return CommandResponse.ofSuccess(result);
}
代码示例来源:origin: alibaba/Sentinel
List<FlowRule> flowRules = JSONArray.parseArray(data, FlowRule.class);
FlowRuleManager.loadRules(flowRules);
if (!writeToDataSource(getFlowDataSource(), flowRules)) {
List<AuthorityRule> rules = JSONArray.parseArray(data, AuthorityRule.class);
AuthorityRuleManager.loadRules(rules);
if (!writeToDataSource(getAuthorityDataSource(), rules)) {
List<DegradeRule> rules = JSONArray.parseArray(data, DegradeRule.class);
DegradeRuleManager.loadRules(rules);
if (!writeToDataSource(getDegradeDataSource(), rules)) {
List<SystemRule> rules = JSONArray.parseArray(data, SystemRule.class);
SystemRuleManager.loadRules(rules);
if (!writeToDataSource(getSystemSource(), rules)) {
代码示例来源:origin: alibaba/Sentinel
@Override
public CommandResponse<String> handle(CommandRequest request) {
String namespace = request.getParam("namespace");
if (StringUtil.isEmpty(namespace)) {
return CommandResponse.ofFailure(new IllegalArgumentException("empty namespace"));
}
String data = request.getParam("data");
if (StringUtil.isBlank(data)) {
return CommandResponse.ofFailure(new IllegalArgumentException("empty data"));
}
try {
data = URLDecoder.decode(data, "UTF-8");
RecordLog.info("[ModifyClusterFlowRulesCommandHandler] Receiving cluster flow rules for namespace <{0}>: {1}", namespace, data);
List<FlowRule> flowRules = JSONArray.parseArray(data, FlowRule.class);
ClusterFlowRuleManager.loadRules(namespace, flowRules);
return CommandResponse.ofSuccess(SUCCESS);
} catch (Exception e) {
RecordLog.warn("[ModifyClusterFlowRulesCommandHandler] Decode cluster flow rules error", e);
return CommandResponse.ofFailure(e, "decode cluster flow rules error");
}
}
代码示例来源:origin: alibaba/Sentinel
@Override
public CommandResponse<String> handle(CommandRequest request) {
String namespace = request.getParam("namespace");
if (StringUtil.isEmpty(namespace)) {
return CommandResponse.ofFailure(new IllegalArgumentException("empty namespace"));
}
String data = request.getParam("data");
if (StringUtil.isBlank(data)) {
return CommandResponse.ofFailure(new IllegalArgumentException("empty data"));
}
try {
data = URLDecoder.decode(data, "UTF-8");
RecordLog.info("[ModifyClusterParamFlowRulesCommandHandler] Receiving cluster param rules for namespace <{0}>: {1}", namespace, data);
List<ParamFlowRule> flowRules = JSONArray.parseArray(data, ParamFlowRule.class);
ClusterParamFlowRuleManager.loadRules(namespace, flowRules);
return CommandResponse.ofSuccess(SUCCESS);
} catch (Exception e) {
RecordLog.warn("[ModifyClusterParamFlowRulesCommandHandler] Decode cluster param rules error", e);
return CommandResponse.ofFailure(e, "decode cluster param rules error");
}
}
代码示例来源:origin: wangdan/AisenWeiBo
@Override
protected <T> T parseResponse(String resultStr, Class<T> responseCls) throws TaskException {
try {
JSONArray jsonArray = JSONArray.parseArray(resultStr);
代码示例来源:origin: zhangyd-c/springboot-learning
/**
* 预解析5此该cron将要执行的时间节点
*
* @param cron 带解析的cron
* @return
* @throws IOException
*/
@RequestMapping("/parseCron")
@ResponseBody
public List<String> parseCron(String cron) throws IOException {
String urlNameString = "http://cron.qqe2.com/CalcRunTime.ashx?CronExpression=" + URLEncoder.encode(cron, "UTF-8");
URL realUrl = new URL(urlNameString);
URLConnection connection = realUrl.openConnection();
connection.setRequestProperty("accept", "*/*");
connection.setRequestProperty("connection", "Keep-Alive");
connection.setRequestProperty("user-agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36");
connection.connect();
StringBuilder result = new StringBuilder();
try (BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()))) {
String line;
while ((line = in.readLine()) != null) {
result.append(line);
}
} catch (Exception e) {
e.printStackTrace();
}
return JSONArray.parseArray(result.toString(), String.class);
}
}
代码示例来源:origin: tianshaojie/AndroidFine
@Override
public void onSuccess(RestApiResponse response) {
mPtrFrame.refreshComplete();
List<SearchShop> list = JSONArray.parseArray(response.body, SearchShop.class);
listView.updateLoadMoreViewText(list);
isLoadAll = list.size() < HttpClient.PAGE_SIZE;
if(pno == 1) {
adapter.clear();
}
adapter.addAll(list);
pno++;
}
代码示例来源:origin: UncleCatMySelf/InChat
public JSONArray getArrayByGroupId(String groupId) {
JSONArray jsonArray = JSONArray.parseArray("[\"1111\",\"2222\",\"3333\"]");
return jsonArray;
}
}
代码示例来源:origin: net.mingsoft/ms-util
/**
* 从json对象集合表达式中得到一个java对象集合</br>
* JSON数据中键的名称必须和对应JAVA对象中bean字段的名称一致</br>
*
* @param <T> 对象值
* @param jsonString json字符串
* @param cls JAVA Bean对象
* @return JAVA bean对象集合list
*/
public static <T> List<T> queryJsonToList(String jsonString,Class<T> cls) {
List<T> list = JSONArray.parseArray(jsonString,cls);
return list;
}
代码示例来源:origin: net.mingsoft/ms-util
/**
* 从json数组中得到相应java数组
*
* @param jsonString json字符串
* @return 返回java数组
*/
public static Object[] getObjectArray4Json(String jsonString) {
JSONArray jsonArray = JSONArray.parseArray(jsonString);
return jsonArray.toArray();
}
代码示例来源:origin: Erik-ly/SprakProject
public static void main(String[] args) {
String json = "[{'学生':'张三','班级':'一班','年级':'大一','科目':'高数','成绩':90},"
+ "{'学生':'李四','班级':'二班','年级':'大一','科目':'高数','成绩':80}]";
JSONArray jsonArray = JSONArray.parseArray(json);
JSONObject jsonObject = jsonArray.getJSONObject(0);
System.out.println(jsonObject.getString("学生"));
}
代码示例来源:origin: ansitech/weixin4j
/**
* 将输出流转换为JSON对象
*
* @return JSONArray对象
* @throws org.weixin4j.WeixinException
*/
public JSONArray asJSONArray() throws WeixinException {
return JSONArray.parseArray(asString());
}
代码示例来源:origin: chanedi/QuickProject
protected List<Sort> parseSort(HttpServletRequest request) {
String sort = request.getParameter("sort");
if (StringUtils.isEmpty(sort)) {
return null;
}
return JSONArray.parseArray(sort, Sort.class);
}
代码示例来源:origin: hujiaweibujidao/Ganks-for-gank.io
/**
* 得到本地的干货的日报的列表
*/
public List<GankIssue> getIssues() throws Exception {
File file = new File(DataHelper.GANKIO_JSON);
return JSONArray.parseArray(CommonTool.getFileContent(file), GankIssue.class);
}
代码示例来源:origin: hujiaweibujidao/Ganks-for-gank.io
/**
* 得到周报列表
*/
public static List<GankIssue> getIssues() {
List<GankIssue> issueList = null;
try {
issueList = JSONArray.parseArray(CommonTool.getFileContent(new File(DataHelper.GANKIO_JSON)), GankIssue.class);
} catch (Exception e) {
e.printStackTrace();
}
return issueList;
}
代码示例来源:origin: XunMengWinter/Now
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_image_list);
ButterKnife.bind(this);
String imagesStr = getIntent().getStringExtra(Constants.KEY_IMAGES_STR);
mList = JSONArray.parseArray(imagesStr, TeaBean.AvatarBean.class);
mRecyclerView.setLayoutManager(new LinearLayoutManager(this));
mMonoImageAdapter = new MonoImageAdapter(this, mList);
mRecyclerView.setAdapter(mMonoImageAdapter);
}
}
代码示例来源:origin: com.aliyun.openservices/aliyun-log
private com.alibaba.fastjson.JSONArray ParseResponseMessageToArrayWithFastJson(ResponseMessage response,
String requestId) throws LogException {
String returnStr = encodeResponseBodyToUtf8String(response, requestId);
try {
return com.alibaba.fastjson.JSONArray.parseArray(returnStr);
} catch (com.alibaba.fastjson.JSONException e) {
throw new LogException(ErrorCodes.BAD_RESPONSE,
"The response is not valid json string : " + returnStr, e,
requestId);
}
}
代码示例来源:origin: aliyun/aliyun-log-java-sdk
private com.alibaba.fastjson.JSONArray ParseResponseMessageToArrayWithFastJson(ResponseMessage response,
String requestId) throws LogException {
String returnStr = encodeResponseBodyToUtf8String(response, requestId);
try {
return com.alibaba.fastjson.JSONArray.parseArray(returnStr);
} catch (com.alibaba.fastjson.JSONException e) {
throw new LogException(ErrorCodes.BAD_RESPONSE,
"The response is not valid json string : " + returnStr, e,
requestId);
}
}
代码示例来源:origin: huangfangyi/YiChat
private List<JSONObject> getMoments() {
JSONArray jsonArray = ACache.get(MomentsFriendActivity.this).getAsJSONArray(cacheKey);
if (jsonArray != null) {
List<JSONObject> list = JSONArray.parseArray(jsonArray.toJSONString(), JSONObject.class);
articles.addAll(list);
}
return articles;
}
代码示例来源:origin: huangfangyi/YiChat
@Override
public List<JSONObject> getData() {
JSONArray jsonArray = ACache.get(monmentsView.getBaseContext()).getAsJSONArray(cacheKey);
if (jsonArray!=null){
List<JSONObject> list = JSONArray.parseArray(jsonArray.toJSONString(), JSONObject.class);
data.addAll(list);
}
return data;
}
public String getBackgroudMoment(){
内容来源于网络,如有侵权,请联系作者删除!