我相信下面的字符串是json格式的,但是当我尝试将字符串加载到json变量中时,我可以轻松地查询和提取数据点,这样就会出错。
jdata = '<pre>{\n "askId": "AAABB110-000011",\n "dateCreated": "2009-09-01T00:00:00.000Z",\n "dateUpdated": "2021-06-24T00:00:00.000Z",\n "owners": [\n {\n "ownerType": "Service-Level Owner",\n "VendorId": "000111222"\n },\n {\n "ownerType": "Technical Owner",\n "CustomerId": "000333444"\n },\n {\n "ownerType": "Business Owner",\n "ServiceId": "000005556"\n }\n ],\n "createdBy": "SYSTEM",\n "lastUpdatedBy": "000667778",\n "applicationName": "Treasury Bank Data",\n "description": "Process Data",\n "aliases": [\n "Treasury Bank Data",\n "Bank Data",\n "Bank Reconciliation",\n "Bank Rec",\n "SERV-X"\n ],\n "billingBusinessSegmentId": 6,\n "category": {\n "categoryId": 1,\n "categoryName": "Application"\n },\n "lifecycleStage": {\n "lifecycleStageId": 3,\n "lifecycleStageName": "Production"\n },\n "acquiredEntity": {\n "acquiredEntityId": 0,\n "acquiredEntityName": "Not Applicable"\n },\n "enclaveEnvironment": {\n "enclaveEnvironmentId": 0,\n "enclaveEnvironmentName": "General Hosting (Internal, Cloud, or Vendor hosted)"\n },\n "softwareType": {\n "softwareTypeId": 7,\n "softwareTypeName": "Vendor Product"\n },\n "infrastructureRequired": false,\n "uhgHelpdeskRequired": false,\n "references": [\n {\n "referenceType": "disaster-recovery",\n "referenceValue": "APPX009919"\n }\n ]\n}\n</pre>'
jsonData = json.loads(jdata)一旦我试图将数据加载到jsonData变量中,下面就会出现错误。
Expecting value: line 1 column 1 (char 0)我的字符串不允许作为json变量加载有什么问题吗?
发布于 2022-03-03 01:12:17
如果去掉html标记,就会得到json:
import json
jdata = '<pre>{\n "askId": "AAABB110-000011",\n "dateCreated": "2009-09-01T00:00:00.000Z",\n "dateUpdated": "2021-06-24T00:00:00.000Z",\n "owners": [\n {\n "ownerType": "Service-Level Owner",\n "VendorId": "000111222"\n },\n {\n "ownerType": "Technical Owner",\n "CustomerId": "000333444"\n },\n {\n "ownerType": "Business Owner",\n "ServiceId": "000005556"\n }\n ],\n "createdBy": "SYSTEM",\n "lastUpdatedBy": "000667778",\n "applicationName": "Treasury Bank Data",\n "description": "Process Data",\n "aliases": [\n "Treasury Bank Data",\n "Bank Data",\n "Bank Reconciliation",\n "Bank Rec",\n "SERV-X"\n ],\n "billingBusinessSegmentId": 6,\n "category": {\n "categoryId": 1,\n "categoryName": "Application"\n },\n "lifecycleStage": {\n "lifecycleStageId": 3,\n "lifecycleStageName": "Production"\n },\n "acquiredEntity": {\n "acquiredEntityId": 0,\n "acquiredEntityName": "Not Applicable"\n },\n "enclaveEnvironment": {\n "enclaveEnvironmentId": 0,\n "enclaveEnvironmentName": "General Hosting (Internal, Cloud, or Vendor hosted)"\n },\n "softwareType": {\n "softwareTypeId": 7,\n "softwareTypeName": "Vendor Product"\n },\n "infrastructureRequired": false,\n "uhgHelpdeskRequired": false,\n "references": [\n {\n "referenceType": "disaster-recovery",\n "referenceValue": "APPX009919"\n }\n ]\n}\n</pre>'
jsonData = json.loads(jdata.lstrip('<pre>').rstrip('</pre>'))
print(jsonData)https://stackoverflow.com/questions/71330930
复制相似问题