无法使用python打开json文件?

2021-08-02 17:43:42 发布

您现在位置:Python中文网/ 问答频道 /正文

 {
    "appKey": "c6e2917da6dcc5e5dc5a57849eba1637ec92f98383c926aed8562154d63eb7fcd51bb57bd1907235ac2a553ab65fa3a29af2a7772829b890d6bc8e1f5a313bf1",
    "appId": "AUDI_SDS_2017_EXT_20151203",
    "cmdName": "DRAGON_NLU_ASR_CMD",
    "appName": "Python",
    "appVersion": "1",
    "language": "deu-DEU",
    "carrier": "carrier",
    "deviceModel": "deviceModel",
    "cmdDict": {
        "dictation_type": "ccpoi_dragondrive_specialized",
        "dictation_language": "deu-DEU",
        "locale": "germany",
        "application": "AUDI_2017",
        "organization_id": "Audi",
        "phone_OS": "4.0",
        "phone_network": "wifi",
        "audio_source": "SpeakerAndMicrophone",
        "location": "<48.396231, 9.972909> +/- 10.00m",
        "application_session_id": "1234567890",
        "utterance_number": "5",
        "ui_langugage": "de",
        "phone_submodel": "nmPhone2,1",
        "application_state_id": "45"
    }
}

上面是我的json文件并保存为ENG_请求数据.json. 我有与上面类似的json文件,并将其保存为DEU_请求数据.json. 你知道吗

import json
import os
scriptPath = os.path.dirname(os.path.abspath(__file__))
ENG_RequestDataFile = scriptPath + "\ENG_RequestData.json"
print ENG_RequestDataFile
DEU_RequestDataFile = scriptPath + "\DEU_RequestData.json"

try:
    with open(ENG_RequestDataFile) as json_file:   
        #print json_file
        JSON_ENGData = json.load(json_file)
        print JSON_ENGData

    with open(DEU_RequestDataFile) as json_file:    
        JSON_DEUData = json.load(json_file)

except:
    print "[ERROR] FILE Cannot be opened"

上面的代码试图打开json文件,但我得到的输出是[ERROR]文件无法打开。我已经指定了脚本路径,而且我的.json文件只在那里。当我打印json路径文件时,它正在准确地打印。有人能告诉我哪里错了吗?你知道吗