【问题标题】:PL/JSON Message ListsPL/JSON 消息列表
【发布时间】:2016-05-20 21:32:15
【问题描述】:

我正在解析存储在 oracle 11g 中的表 CLOB 中的 json 字符串。这个过程是一个长解析例程的一部分,它解析数据并将值存储在另一个表中,我刚刚注意到我的部分数据没有流出。 json 使用 JSONLint 解析和验证。所以我简化了解析,试图找出哪里出错了。

所以我的 json 从我的表中出来看起来像这样。

{
    "JSON_data": {
        "plant_id": "3006",
        "transmit_time": "2015-12-18 11:57:45",
        "messages": [{
            "work_msg": {
                "msg_time": "2015-06-23 04:54:17",
                "trigger_type": "interval",
                "vert_correction": 358.3,
                "ch_latitude": 37.916302,
                "ch_longitude": -87.487365,
                "ch_heading": 212.3,
                "ch_cable_port": 1029.79,
                "ch_cable_stbd": 348.63,
                "ch_depth": -27.03,
                "slurry_velocity": 25.71,
                "slurry_density": 1.02,
                "ch_rpm": 205.49,
                "ch_psi": 540.89,
                "prod_instantaneous": 0,
                "prod_cumulative": 1216.100000,
                "outfall_latitude": 37.915967,
                "outfall_longitude": -87.484369,
                "outfall_heading": 120.7,
                "pump_entries": [{
                    "pump_name": "main",
                    "vacuum": 12.73,
                    "outlet_psi": 22.88
                }],
                "spud_entries": [{
                    "position": 6
                }]
            },
            "pipe_length_event": {
                "msg_time": "2015-06-23 04:54:17",
                "length_floating": 970
            }
        }]
    }
}

我的解析是正确地找到并处理“work_msg”数据。这是我没有得到的“pipe_length_event”数据。下面是我简化的 pl/sql 过程。

DECLARE

vCONTENT            CLOB;
v_parent_json           json;
v_json_message_list         json_list;
v_json_message_list_value   json_value;
v_parent_json_value         json_value;


BEGIN

SELECT CONTENT INTO vCONTENT FROM SJM_TEMP4;

v_parent_json := json(vCONTENT);
v_parent_json := json(v_parent_json.get(1));

v_json_message_list := json_list(v_parent_json.get('messages'));

DBMS_OUTPUT.PUT_LINE(v_json_message_list.count);

for message_loop_counter in 1 ..v_json_message_list.count loop
    v_parent_json_value := json(v_json_message_list.get(message_loop_counter)).get(1);

    DBMS_OUTPUT.PUT_LINE(v_parent_json_value.mapname);
END LOOP;

END;

我的 dbms_output 首先给我的子列表计数为 1。不是 2,所以我的解析甚至没有将“pipe_length_event”识别为“消息”的子列表。

如何使用此过程获取“pipe_length_event”数据?我几乎可以肯定这在过去是有效的,所以我的第一个想法是 json 的格式不同。 json格式不正确吗?

提前致谢。

【问题讨论】:

    标签: json oracle11g pljson


    【解决方案1】:

    找到了!!

    问题实际上是 JSON 格式。下面是正确的格式。 “work_msg”列表未关闭,因此无法识别“pipe_length_event”列表。

    {
        "JSON_data": {
            "plant_id": "3006",
            "transmit_time": "2015-12-18 11:57:45",
            "messages": [{
                "work_msg": {
                    "msg_time": "2015-06-23 04:54:17",
                    "trigger_type": "interval",
                    "vert_correction": 358.3,
                    "ch_latitude": 37.916302,
                    "ch_longitude": -87.487365,
                    "ch_heading": 212.3,
                    "ch_cable_port": 1029.79,
                    "ch_cable_stbd": 348.63,
                    "ch_depth": -27.03,
                    "slurry_velocity": 25.71,
                    "slurry_density": 1.02,
                    "ch_rpm": 205.49,
                    "ch_psi": 540.89,
                    "prod_instantaneous": 0,
                    "prod_cumulative": 1216.100000,
                    "outfall_latitude": 37.915967,
                    "outfall_longitude": -87.484369,
                    "outfall_heading": 120.7,
                    "pump_entries": [{
                        "pump_name": "main",
                        "vacuum": 12.73,
                        "outlet_psi": 22.88
                    }],
                    "spud_entries": [{
                        "position": 6
                    }]
                }
            }, {
                "pipe_length_event": {
                    "msg_time": "2015-06-23 04:54:17",
                    "length_floating": 970
                }
            }]
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-05-14
      • 1970-01-01
      • 2017-08-21
      • 1970-01-01
      • 2021-11-20
      • 2017-02-08
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多