如何在Java中解析不带名称的json数组(来自json文件)?

时间:2019-07-10 19:02:43

标签: arrays json

我有一个包含未命名数组的json文件(如下所示)。我需要在我的Java程序中解析此json文件,并动态地遍历元素。

Json文件具有以下内容:

     $this->medicalIdentifiers->user_id = $doctorProfile['user_id'];
            $this->medicalIdentifiers->medical_credentials = $doctorProfile['medical_credentials'];
            $this->medicalIdentifiers->registration_number = $doctorProfile['registration_number'];
            $this->medicalIdentifiers->registration_expiration_date = $doctorProfile['registration_expiration_date'];
            $this->medicalIdentifiers->dea_number = $doctorProfile['dea_number'];
            $this->medicalIdentifiers->dea_expiration_date = $doctorProfile['dea_expiration_date'];
            $this->medicalIdentifiers->dea_issue_date = $doctorProfile['dea_issue_date'];
            $this->medicalIdentifiers->npi_number = $doctorProfile['npi_number'];
            $this->medicalIdentifiers->billing_title = $doctorProfile['billing_title'];
            $this->medicalIdentifiers->billing_employment_type = $doctorProfile['billing_employment_type'];
            $this->medicalIdentifiers->other_employment_type = $doctorProfile['other_employment_type'];
            $this->medicalIdentifiers->nadean_number = $doctorProfile['nadean_number'];
            $this->medicalIdentifiers->upin = $doctorProfile['upin'];
            $this->medicalIdentifiers->wcb_authorization = $doctorProfile['wcb_authorization'];
            $this->medicalIdentifiers->wcb_rating_code = $doctorProfile['wcb_rating_code'];
            $this->medicalIdentifiers->wcb_date_of_issue = $doctorProfile['wcb_date_of_issue'];
            $this->medicalIdentifiers->hospital_privileges = $doctorProfile['hospital_privileges'];
            $this->medicalIdentifiers->save();

//读取json文件

{
    [   
        {

            "OutletPipeTemperatureCV": 31.5,
            "ChocolateMixingStageTemperatureCV": 30.89999,
            "WaterCoolingStageTemperatureCV": 14.5,
            "WaterMixingStageTemperatureCV": 31.5,
            "ChocolateHeatingStageTemperatureCV": "",
            "ChocolateCoolingStageTemperatureSV": "",
            "TimeStamp": "2019 - 07 - 09 12: 58: 01.776",
            "WaterHeatingStageTemperatureSV": "",
            "OutletPipeTemperatureSV": "",
            "ChocolateMixingStageTemperatureSV": ""

        },
        {
            "OutletPipeTemperatureCV": 31.5,
            "ChocolateMixingStageTemperatureCV": 30.8999,
            "WaterCoolingStateTemperatureCV": 14.600000381469727,
            "WaterMixingStateTemperatureCV": 31.5,
            "ChocolateHeatingStageTemperatureCV": "",
            "ChocolateCoolingStageTemperatureSV": "",
            "TimeStamp": "2019 - 07 - 09 12: 55: 46.674",
            "WaterHeatingStageTemperatureSV": "",
            "OutletPipeTemperatureSV": "",
            "ChocolateMixingStageTemperatureSV": ""
        },
        {
            "OutletPipeTemperatureCV": 31.5,
            "ChocolateMixingStageTemperatureCV": 30.8999,
            "WaterCoolingStateTemperatureCV": 14.600000381469727,
            "WaterMixingStateTemperatureCV": 31.5,
            "ChocolateHeatingStageTemperatureCV": "",
            "ChocolateCoolingStageTemperatureSV": "",
            "TimeStamp": "2019 - 07 - 09 12: 55: 46.674",
            "WaterHeatingStageTemperatureSV": "",
            "OutletPipeTemperatureSV": "",
            "ChocolateMixingStageTemperatureSV": ""
        }

    ]
}

我试图将json数据传递到json对象中,但是找不到一种遍历它的方法。

我在SO中看到了其他帖子,其中提到(如下所述),它只是在创建Json数组并对其进行迭代时将Json String作为参数传递。

FileReader reader = new FileReader("C:\\JSONInfo.txt");

JSONParser jsonPar = new JSONParser();
JSONObject jsonObj = (JSONObject) jsonPar.parse(reader);

但是,在使用Json文件的情况下,我感到困惑。如果有人可以为我提供解析json文件并根据记录数进行遍历的逻辑,那将非常有帮助,因为我是json的新手。

0 个答案:

没有答案