JAVA 解析複雜的json字串
原記錄在有道雲筆記。
public String pddGetOrders() {
String orderidinfo=pddMap();
System.out.println(orderidinfo);
Map<String, Object> results = JsonToMap.parseJSON2Map(orderidinfo);
Map<String, Object> order= (Map<String, Object>) results.get("order");
System.out.println(order);
String orderCount=String.valueOf(order.get("orderCount"));
int page=Integer.valueOf((String) order.get("page"));
System.out.println(orderCount);
System.out.println(page);
JSONArray array = JSONArray.fromObject(order.get("orderList"));
System.out.println(array);
//遍歷得到所有id,放進pddidslist集合裡
List<String> pddidslist=new ArrayList<String>();
do{
for (int i = 0; i < array.size(); i++) {
Map map= (Map) array.get(i);
String orderid=(String) map.get("orderSN");
System.out.println("訂單ID:"+orderid);
pddidslist.add(orderid);
System.out.println(pddidslist);
}
page++;
}
while(orderCount=="100");
// pddidslist轉換成陣列
String[] arrays = new String[pddidslist.size()];
for (int j = 0; j < pddidslist.size(); j++) {
arrays[j] = pddidslist.get(j);
}
List<Order> psidslist = orderService.selectPddOrders(arrays);
for(int k = 0; k < psidslist.size(); k++){
String psid=psidslist.get(k).getId();
for(int j = 0; j < pddidslist.size(); j++){
if (psid.equals(pddidslist.get(j))) {
//去掉資料庫中已有的
pddidslist.remove(j);
break;
}
}
}
System.out.println(pddidslist);
System.out.println("+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++");
return "redirect:";
}
public String pddMap() {
Map<String, Object> order = new HashMap<String, Object>();
Map<String, Object> result = new HashMap<String, Object>();
Map<String, Object> item = new HashMap<String, Object>();
item.put("orderSN", "151210-65418251031");
Map<String, Object> item1 = new HashMap<String, Object>();
item1.put("orderSN", "151214-77466052010");
Map<String, Object> item2 = new HashMap<String, Object>();
item2.put("orderSN", "201612251706202020995");
Map<String, Object> item3 = new HashMap<String, Object>();
item3.put("orderSN", "201612251654555555680");
List<Map<String, Object>> orders = new ArrayList<Map<String, Object>>();
orders.add(item);
orders.add(item1);
orders.add(item2);
orders.add(item3);
result.put("orderCount", "4");
result.put("page", "1");
result.put("result", "1");
result.put("cause", "");
result.put("orderList", orders);
order.put("order", result);
String d=JSON.toJSONString(order);
return d;
}
- String parameter = {
- success : 0,
- errorMsg : "錯誤訊息",
- data : {
- total : "總記錄數",
- rows : [ {
- id : "任務ID",
- workName : "任務名稱",
- assigneeName : "經辦人姓名",
- name : "流程步驟名稱",
- processInstanceInitiatorName : "發起人",
- processInstanceStartTime : "發起時間",
- createTime : "到達時間",
- dueDate : "截止時間"
- }, {
- id : "ID",
- workName : "名稱",
- assigneeName : "經辦人",
- name : "流程",
- processInstanceInitiatorName : "發起人",
- processInstanceStartTime : "發起",
- createTime : "到達",
- dueDate : "截止"
- } ]
- }
- };
-
- JSONObject jsonObject =JSONObject.fromObject(parameter);
- System.out.println("success:"+jsonObject.get("success"));
- System.out.println("errorMsg:"+jsonObject.get("errorMsg"));
- System.err.println("total:"+jsonObject.getJSONObject("data").get("total"));
- JSONObject data = jsonObject.getJSONObject("data");
- JSONArray jsonArray = data.getJSONArray("row");
- JSONObject row = null;
- for (int i = 0; i < jsonArray.size(); i++) {
- row = jsonArray.getJSONObject(i);
- System.out.println("id:"+row.get("id"));
- System.out.println("workName:"+row.get("workName"));
- System.out.println("assigneeName:"+row.get("assigneeName"));
- System.out.println("name:"+row.get("name"));
- System.out.println("processInstanceInitiatorName:"+row.get("processInstanceInitiatorName"));
- System.out.println("processInstanceStartTime:"+row.get("processInstanceStartTime"));
- System.out.println("createTime:"+row.get("createTime"));
- System.out.println("dueDate:"+row.get("dueDate"));
- }
相關文章
- [譯]在 Flutter 中解析複雜的 JSONFlutterJSON
- Python3 解析複雜結構的 jsonPythonJSON
- 學會用 Go 解析複雜 JSON 的思路GoJSON
- Java基礎-處理json字串解析案例JavaJSON字串
- 一個複雜的json例子JSON
- 使用clarinet(browser&node.js)解析重複key值的json字串Node.jsJSON字串
- 使用ajax請求傳送複雜的json資料型別,並解決fastjson解析複雜的json資料型別的問題JSON資料型別AST
- 解析Json字串的三種方法JSON字串
- Flutter解析複雜JSON泛型方案--拋磚引玉篇FlutterJSON泛型
- 字串值提取工具-09-java 執行 json 解析, json-path字串JavaJSON
- java生成json字串的方法JavaJSON字串
- PHP 陣列排序(複雜字串)PHP陣列排序字串
- C#解析JSON字串總結C#JSON字串
- JSONObject與JSONArray 解析JSON格式字串JSONObject字串
- java解析json listJavaJSON
- json字串返回的資料有重複的資料JSON字串
- Spring Boot 中使用 JSON Schema 來校驗複雜JSON資料Spring BootJSON
- Java JSON組成和解析JavaJSON
- T-SQL——自定義函式解析JSON字串SQL函式JSON字串
- json 物件與json 字串的區別。JSON物件字串
- FastJSON解析Json字串(反序列化為List、Map)ASTJSON字串
- Java設定JSON字串引數編碼JavaJSON字串
- xml字串轉JSON字串XML字串JSON
- 三分鐘帶你解析Hive中的json字串(詳細!)HiveJSON字串
- Java雜記17—String全面解析Java
- 字串與JSON字串JSON
- 使用Python處理複雜字串的必殺技-re.sub()的妙用Python字串
- 4. JSON字串是如何被解析的?JsonParser瞭解一下JSON字串
- DDD之理解複雜度、尊重複雜度、掌控複雜度複雜度
- 複雜度分析的套路及常見的複雜度複雜度
- Spark SQL:JSON資料來源複雜綜合案例實戰SparkSQLJSON
- Json物件與Json字串互轉JSON物件字串
- 字串雜湊字串
- encoding/json 怎麼將日期字串解析成time.Time格式EncodingJSON字串
- java json解析jar包基本使用記錄JavaJSONJAR
- Java 嵌入指令碼快速解析多層 jsonJava指令碼JSON
- 字串查詢(字串雜湊)字串
- JAVA 解析html 型別字串(使用jsoup)JavaHTML型別字串JS