-2

嗨,我需要将 operationsList 数组下的 json 对象解析为关系字段和对象,但这里的技巧是我粘贴的示例在 operationsList 数组下有七个对象,我的代码能够单独解析每个 json 对象,但您需要使用以下函数能够自动选择每个 json 对象。

我需要在 pgadmin $ 中执行 postgres 9.6 的答案

注意:我尝试了几个小时使用所有功能

代码粘贴在下面

{
  "header" : {
    "tasklistid" : "RC016753",
    "planningPlant" : "ECL",
    "status" : "Z03",
    "title" : "725307-STG 1 LPT NZZ",
    "parentRouterId" : "",
    "enginecode" : "5B",
    "structureNode" : "5B_72530015200",
    "routerType" : "INR",
    "disassemblyLocation" : "TL725300",
    "latestReleaseDate" : "31.12.8888",
    "planningReference" : "INR-725300"
  },
  "operationsList" : [ {
    "order" : "0010",
    "text" : "232-003-IN PROCESS - FPI",
    "workCenter" : "248",
    "controlKey" : "ZQP3",
    "details" : {
      "longText" : "232-003-IN PROCESS - FPI FPI : Floroscent penetration Inspection This is Long text to test the API",
      "MICS" : [ {
        "order" : "0010",
       "MICNumber" : "C0000100",
        "Plant" : "ECL",
        "version" : "000003"
      }, {
        "order" : "0020",
        "MICNumber" : "C0175399",
        "Plant" : "ECL",
        "version" : "000001"
      }, {
        "order" : "0030",
        "MICNumber" : "C0175400",
        "Plant" : "ECL",
        "version" : "000001"
      } ],
      "dependencies" : [ ],
      "documents" : [ {
        "Number" : "5B/ZSC-ECL-0041176",
        "Type" : "ZSC",
        "version" : "00",
        "order" : "0500"
      }, {
        "Number" : "5B/ZSC-ECL-0041175",
        "Type" : "ZSC",
        "version" : "00",
        "order" : "0510"
      }, {
        "Number" : "5B/ZSC-ECL-0041177",
        "Type" : "ZSC",
        "version" : "00",
        "order" : "0520"
      }, {
        "Number" : "5B/ZSC-ECL-0041178",
        "Type" : "ZSC",
        "version" : "00",
        "order" : "0530"
      } ]
    }
  }, {
    "order" : "0020",
    "text" : "307-004-BENCHING",
    "workCenter" : "358",
    "controlKey" : "SM01",
    "details" : {
      "longText" : "",
      "MICS" : [ ],
      "dependencies" : [ ],
      "documents" : [ ]
    }
  }, {
    "order" : "0030",
    "text" : "110-005-CHEMICAL CLEANING",
    "workCenter" : "048",
    "controlKey" : "ZQP1",
    "details" : {
      "longText" : "",
      "MICS" : [ {
        "order" : "0010",
        "MICNumber" : "C0006683",
        "Plant" : "ECL",
        "version" : "000001"
      } ],
      "dependencies" : [ ],
      "documents" : [ ]
    }
  }, {
    "order" : "0040",
    "text" : "310-001-TIG WELDING",
    "workCenter" : "295",
    "controlKey" : "ZQP1",
    "details" : {
      "longText" : "",
      "MICS" : [ {
        "order" : "0010",
        "MICNumber" : "C0020962",
        "Plant" : "ECL",
        "version" : "000001"
      }, {
        "order" : "0020",
        "MICNumber" : "C0006552",
        "Plant" : "ECL",
        "version" : "000001"
      }, {
        "order" : "0030",
        "MICNumber" : "C0006511",
        "Plant" : "ECL",
        "version" : "000001"
      } ],
      "dependencies" : [ ],
      "documents" : [ {
        "Number" : "5B/ZSC-ECL-0041175",
        "Type" : "ZSC",
        "version" : "00",
        "order" : "0500"
      }, {
        "Number" : "5B/ZSC-ECL-0041176",
        "Type" : "ZSC",
        "version" : "00",
        "order" : "0510"
      }, {
        "Number" : "5B/ZSC-ECL-0041177",
        "Type" : "ZSC",
        "version" : "00",
        "order" : "0520"
      }, {
        "Number" : "5B/ZSC-ECL-0041178",
        "Type" : "ZSC",
        "version" : "00",
        "order" : "0530"
      } ]
    }
  }, {
    "order" : "0050",
    "text" : "307-005-BENCHING",
    "workCenter" : "358",
    "controlKey" : "SM01",
    "details" : {
      "longText" : "",
      "MICS" : [ ],
      "dependencies" : [ ],
      "documents" : [ {
        "Number" : "5B/ZSC-ECL-0041175",
        "Type" : "ZSC",
        "version" : "00",
        "order" : "0500"
      }, {
        "Number" : "5B/ZSC-ECL-0041176",
        "Type" : "ZSC",
        "version" : "00",
        "order" : "0510"
      }, {
        "Number" : "5B/ZSC-ECL-0041177",
        "Type" : "ZSC",
        "version" : "00",
        "order" : "0520"
      }, {
        "Number" : "5B/ZSC-ECL-0041178",
        "Type" : "ZSC",
        "version" : "00",
        "order" : "0530"
      } ]
    }
  }, {
    "order" : "0060",
    "text" : "220-001-IN PROCESS DIMENSIONAL INSP",
    "workCenter" : "358",
    "controlKey" : "ZQP1",
    "details" : {
      "longText" : "",
      "MICS" : [ {
        "order" : "0010",
        "MICNumber" : "C0027739",
        "Plant" : "ECL",
        "version" : "000001"
      } ],
      "dependencies" : [ ],
      "documents" : [ {
        "Number" : "5B/ZSC-ECL-0041175",
        "Type" : "ZSC",
        "version" : "00",
        "order" : "0500"
      }, {
        "Number" : "5B/ZSC-ECL-0041176",
        "Type" : "ZSC",
        "version" : "00",
        "order" : "0510"
      }, {
        "Number" : "5B/ZSC-ECL-0041177",
        "Type" : "ZSC",
        "version" : "00",
        "order" : "0520"
      }, {
        "Number" : "5B/ZSC-ECL-0041178",
        "Type" : "ZSC",
        "version" : "00",
        "order" : "0530"
      } ]
    }
  }, {
    "order" : "0070",
    "text" : "110-006-CHEMICAL CLEANING",
    "workCenter" : "048",
    "controlKey" : "ZQP1",
    "details" : {
      "longText" : "",
      "MICS" : [ {
        "order" : "0010",
        "MICNumber" : "C0006683",
        "Plant" : "ECL",
        "version" : "000001"
      } ],
      "dependencies" : [ ],
      "documents" : [ ]
    }
  } ]
}

请让我知道执行此操作的正确方法,并随时发表您的想法。

4

2 回答 2

0

它的 JSON 列,而不是 JSONB 我在 JSON 列中有整个 JSON 代码(上面粘贴),并且我有操作表,其中列是 order、workcenter、controlkey、table 中的文本,所以我需要从 JSON 对象中选择值并插入将这些值放入列中,因此我可以使用此查询来做到这一点

INSERT INTO public.operation(
 order_1, text, workcenter_number, control_key, long_text)
  (select 

router_payload::json #> '{operationsList, 5}'->> 'order', router_payload ::json #> '{operationsList, 5}' ->> 'text',

router_payload::json #> '{operationsList, 5}'->> 'workCenter',

router_payload::json #> '{operationsList, 5}' ->> 'controlKey', router_payload #> '{operationsList, 5}'-> 'details' ->>'longText',

来自 public.router_data );

但是我的问题如果您在查询中看到我正在指定 {operation,5} 我不想给出我试图使其成为循环或在我执行查询时需要选择所有操作的东西

于 2017-03-16T17:29:54.643 回答
0
ArrayList<operationsList> objOperationsList=new ArrayList<>();

class operationsList

{

String order;

String text;

String workCenter;

String controlKey;

Details objDetails;

}

class Details

{

   String longText;

ArrayList<MICS> objMICS=new ArrayList<>();

   ArrayList<Dependencies> objDependencies=new ArrayList<>();

   ArrayList<Documents> objDocuments=new ArrayList<>();

}

class MICS {}

class Dependencies {}

class Documents {}
于 2017-03-16T14:00:35.173 回答