2016-02-10 29 views
0

我正在解析存儲在oracle 11g中的表CLOB中的json字符串。此過程是解析數據並將值存儲在另一個表中的長解析例程的一部分,我剛剛注意到我的部分數據沒有出來。 json使用JSONLint解析和驗證。所以我簡化了解析,試圖找出我要出錯的地方。PL/JSON消息列表

所以我的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格式不正確嗎?

在此先感謝。

回答

0

發現了!

問題實際上是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 
      } 
     }] 
    } 
}