我正在尝试将以下数据转换为JSON
使用 python,例如import json
. 实际上,我最初以为我正在接收 JSON 数据,直到我回显它并找到以下内容。
不幸的是,我从 SOAP 服务接收到以下数据,因此无法控制我如何接收它。
无论如何,下面看起来是否有任何可以解析的结构?还是我必须逐行浏览并手动转换它?它看起来不像我以前见过的任何东西,即使一些变量名称看起来像是 XML,或者最初是 XML。
我只对stopData[]
数组的值感兴趣,如果这可以简化事情的话,就在一半以上!
作为记录,我尝试使用 JSON 解析器对其进行解析,如下所示,但它无法识别:
data = json.loads(rawData)
data['StopData']
I also tried:
data = json.loads(rawData)
但都没有奏效。这是我必须使用的数据:
('schema', [(schema){
_id = "NewDataSet"
element[] =
(element){
_UseCurrentLocale = "true"
_IsDataSet = "true"
_MainDataTable = "StopData"
_name = "NewDataSet"
complexType[] =
(complexType){
choice[] =
(choice){
_maxOccurs = "unbounded"
_minOccurs = "0"
element[] =
(element){
_name = "StopData"
complexType[] =
(complexType){
sequence[] =
(sequence){
element[] =
(element){
_type = "xs:dateTime"
_name = "ServiceDelivery_ResponseTimestamp"
_minOccurs = "0"
},
(element){
_type = "xs:string"
_name = "ServiceDelivery_ProducerRef"
_minOccurs = "0"
},
(element){
_type = "xs:boolean"
_name = "ServiceDelivery_Status"
_minOccurs = "0"
},
(element){
_type = "xs:boolean"
_name = "ServiceDelivery_MoreData"
_minOccurs = "0"
},
(element){
_type = "xs:string"
_name = "StopMonitoringDelivery_Version"
_minOccurs = "0"
},
(element){
_type = "xs:dateTime"
_name = "StopMonitoringDelivery_ResponseTimestamp"
_minOccurs = "0"
},
(element){
_type = "xs:string"
_name = "StopMonitoringDelivery_RequestMessageRef"
_minOccurs = "0"
},
(element){
_type = "xs:dateTime"
_name = "MonitoredStopVisit_RecordedAtTime"
_minOccurs = "0"
},
(element){
_type = "xs:string"
_name = "MonitoredStopVisit_MonitoringRef"
_minOccurs = "0"
},
(element){
_type = "xs:string"
_name = "MonitoredVehicleJourney_LineRef"
_minOccurs = "0"
},
(element){
_type = "xs:string"
_name = "MonitoredVehicleJourney_DirectionRef"
_minOccurs = "0"
},
(element){
_type = "xs:string"
_name = "FramedVehicleJourneyRef_DataFrameRef"
_minOccurs = "0"
},
(element){
_type = "xs:string"
_name = "FramedVehicleJourneyRef_DatedVehicleJourneyRef"
_minOccurs = "0"
},
(element){
_type = "xs:string"
_name = "MonitoredVehicleJourney_PublishedLineName"
_minOccurs = "0"
},
(element){
_type = "xs:string"
_name = "MonitoredVehicleJourney_OperatorRef"
_minOccurs = "0"
},
(element){
_type = "xs:string"
_name = "MonitoredVehicleJourney_DestinationRef"
_minOccurs = "0"
},
(element){
_type = "xs:string"
_name = "MonitoredVehicleJourney_DestinationName"
_minOccurs = "0"
},
(element){
_type = "xs:boolean"
_name = "MonitoredVehicleJourney_Monitored"
_minOccurs = "0"
},
(element){
_type = "xs:boolean"
_name = "MonitoredVehicleJourney_InCongestion"
_minOccurs = "0"
},
(element){
_type = "xs:string"
_name = "MonitoredVehicleJourney_BlockRef"
_minOccurs = "0"
},
(element){
_type = "xs:string"
_name = "MonitoredVehicleJourney_VehicleRef"
_minOccurs = "0"
},
(element){
_type = "xs:string"
_name = "MonitoredCall_VisitNumber"
_minOccurs = "0"
},
(element){
_type = "xs:boolean"
_name = "MonitoredCall_VehicleAtStop"
_minOccurs = "0"
},
(element){
_type = "xs:dateTime"
_name = "MonitoredCall_AimedArrivalTime"
_minOccurs = "0"
},
(element){
_type = "xs:dateTime"
_name = "MonitoredCall_ExpectedArrivalTime"
_minOccurs = "0"
},
(element){
_type = "xs:dateTime"
_name = "MonitoredCall_AimedDepartureTime"
_minOccurs = "0"
},
(element){
_type = "xs:dateTime"
_name = "MonitoredCall_ExpectedDepartureTime"
_minOccurs = "0"
},
(element){
_type = "xs:dateTime"
_name = "Timestamp"
_minOccurs = "0"
},
},
},
},
},
},
},
}])('diffgram', [(diffgram){
DocumentElement[] =
(DocumentElement){
StopData[] =
(StopData){
_id = "StopData1"
_rowOrder = "0"
ServiceDelivery_ResponseTimestamp[] =
"2013-01-21T20:57:40.33+00:00",
ServiceDelivery_ProducerRef[] =
"bac",
ServiceDelivery_Status[] =
"true",
ServiceDelivery_MoreData[] =
"false",
StopMonitoringDelivery_Version[] =
"1.0",
StopMonitoringDelivery_ResponseTimestamp[] =
"2013-01-21T20:57:40.333+00:00",
StopMonitoringDelivery_RequestMessageRef[] =
"0",
MonitoredStopVisit_RecordedAtTime[] =
"2013-01-21T20:57:40.333+00:00",
MonitoredStopVisit_MonitoringRef[] =
"02371",
MonitoredVehicleJourney_LineRef[] =
"27",
MonitoredVehicleJourney_DirectionRef[] =
"Inbound",
FramedVehicleJourneyRef_DataFrameRef[] =
"2013-01-21",
FramedVehicleJourneyRef_DatedVehicleJourneyRef[] =
"4215",
MonitoredVehicleJourney_PublishedLineName[] =
"77A",
MonitoredVehicleJourney_OperatorRef[] =
"bac",
MonitoredVehicleJourney_DestinationRef[] =
"00354",
MonitoredVehicleJourney_DestinationName[] =
"Ringsend Rd via Tymon Park",
MonitoredVehicleJourney_Monitored[] =
"true",
MonitoredVehicleJourney_InCongestion[] =
"false",
MonitoredVehicleJourney_BlockRef[] =
"027023A:34",
MonitoredVehicleJourney_VehicleRef[] =
"33521",
MonitoredCall_VisitNumber[] =
"39",
MonitoredCall_VehicleAtStop[] =
"false",
MonitoredCall_AimedArrivalTime[] =
"2013-01-21T21:21:00+00:00",
MonitoredCall_ExpectedArrivalTime[] =
"2013-01-21T21:20:12+00:00",
MonitoredCall_AimedDepartureTime[] =
"2013-01-21T21:21:00+00:00",
MonitoredCall_ExpectedDepartureTime[] =
"2013-01-21T21:20:12+00:00",
Timestamp[] =
"2013-01-21T20:57:40.627+00:00",
},
(StopData){
_id = "StopData2"
_rowOrder = "1"
ServiceDelivery_ResponseTimestamp[] =
"2013-01-21T20:57:40.33+00:00",
ServiceDelivery_ProducerRef[] =
"bac",
ServiceDelivery_Status[] =
"true",
ServiceDelivery_MoreData[] =
"false",
StopMonitoringDelivery_Version[] =
"1.0",
StopMonitoringDelivery_ResponseTimestamp[] =
"2013-01-21T20:57:40.333+00:00",
StopMonitoringDelivery_RequestMessageRef[] =
"0",
MonitoredStopVisit_RecordedAtTime[] =
"2013-01-21T20:57:40.333+00:00",
MonitoredStopVisit_MonitoringRef[] =
"02371",
MonitoredVehicleJourney_LineRef[] =
"27",
MonitoredVehicleJourney_DirectionRef[] =
"Inbound",
FramedVehicleJourneyRef_DataFrameRef[] =
"2013-01-21",
FramedVehicleJourneyRef_DatedVehicleJourneyRef[] =
"4061",
MonitoredVehicleJourney_PublishedLineName[] =
"77A",
MonitoredVehicleJourney_OperatorRef[] =
"bac",
MonitoredVehicleJourney_DestinationRef[] =
"00354",
MonitoredVehicleJourney_DestinationName[] =
"Ringsend Rd via Tymon Park",
MonitoredVehicleJourney_Monitored[] =
"true",
MonitoredVehicleJourney_InCongestion[] =
"false",
MonitoredVehicleJourney_BlockRef[] =
"027008:34",
MonitoredVehicleJourney_VehicleRef[] =
"33204",
MonitoredCall_VisitNumber[] =
"39",
MonitoredCall_VehicleAtStop[] =
"false",
MonitoredCall_AimedArrivalTime[] =
"2013-01-21T21:44:00+00:00",
MonitoredCall_ExpectedArrivalTime[] =
"2013-01-21T21:44:00+00:00",
MonitoredCall_AimedDepartureTime[] =
"2013-01-21T21:44:00+00:00",
MonitoredCall_ExpectedDepartureTime[] =
"2013-01-21T21:44:00+00:00",
Timestamp[] =
"2013-01-21T20:57:40.627+00:00",
},
},
}])