关于json数组的解析
2016-07-27 00:00
417 查看
摘要: 调用接口返回String类型的json数组
调用接口返回String类型
public String send(String startDate, String endDate, String times, String type) {
String url = PropertiesUtils.getProperty("Url");
Map<String, String> postParam = new HashMap<String, String>();
postParam.put("startDate",startDate);
postParam.put("endDate",endDate);
postParam.put("times",times);
postParam.put("type",type);
String dsjString= null;
try {
dsjString = HttpClientUtil.getDataByHttpClientFormPost(url,postParam);
} catch (Exception e) {
e.printStackTrace();
}
return dsjString;
}
if (dsjString != null && dsjString != ""){
JSONObject ret = JSONUtils.parseObject(dsjString);
if (ret != null && ret.containsKey("code") && ret.getIntValue("code") == 0){
JSONArray jsonArray = ret.getJSONArray("data");
if (CollectionUtils.isNotEmpty(jsonArray)){
int iSize = jsonArray.size();
for (int i = 0 ; i < iSize ; i++){
JSONObject json = new JSONObject();
try {
json = jsonArray.getJSONObject(i);
} catch (JSONException e) {
e.printStackTrace();
}
if (json.getInteger("count") == 1){
time1 = json.get("nOrders");
}
}
调用接口返回String类型
public String send(String startDate, String endDate, String times, String type) {
String url = PropertiesUtils.getProperty("Url");
Map<String, String> postParam = new HashMap<String, String>();
postParam.put("startDate",startDate);
postParam.put("endDate",endDate);
postParam.put("times",times);
postParam.put("type",type);
String dsjString= null;
try {
dsjString = HttpClientUtil.getDataByHttpClientFormPost(url,postParam);
} catch (Exception e) {
e.printStackTrace();
}
return dsjString;
}
if (dsjString != null && dsjString != ""){
JSONObject ret = JSONUtils.parseObject(dsjString);
if (ret != null && ret.containsKey("code") && ret.getIntValue("code") == 0){
JSONArray jsonArray = ret.getJSONArray("data");
if (CollectionUtils.isNotEmpty(jsonArray)){
int iSize = jsonArray.size();
for (int i = 0 ; i < iSize ; i++){
JSONObject json = new JSONObject();
try {
json = jsonArray.getJSONObject(i);
} catch (JSONException e) {
e.printStackTrace();
}
if (json.getInteger("count") == 1){
time1 = json.get("nOrders");
}
}
相关文章推荐
- Javascript 设计模式学习之二 Module(模块)模式
- Javascript 设计模式学习之三 Singleton(单例)模式
- 【笔记】JS事件模型再复习之笔记
- javaScript操作cookie
- FastJson的使用
- JS中使用EL表达式
- 常见JSP中文乱码例子及其解决方法
- Javascript事件委托
- javascript获取网页各种高宽及位置总结
- JavaScript的原型链学习研究
- javascript中的对象字面量为啥这么酷
- 练习json读取中文
- javascript对文档对象模型DOM的基本操作学习笔记
- JavaScript replace()方法
- 《JavaScript高级程序设计》 - 读书笔记 - 第5章 引用类型
- 在JavaScript中自定义对象
- 详解JSP九大内置对象
- JavaScript的OO思想(一)
- js拖拽效果
- QQZiFramework笔记:entityTable与erp.public.js使用进阶(查询条件、自定义行显示)