在java中读取JSONObject值时出错

时间:2017-01-04 14:40:21

标签: java json

enter image description here我有一个像这样的JSON

{"dlCovs": 
    {
      "covabbrv":["MCWG","LMV"],
      "dcIssuedt":["dd-MM-yyyy  TEST","dd-MM-yyyy  TEST2"],
      "vecatg":["dd-MM-yyyy  TEST3 ","dd-MM-yyyy  TEST4"]},
      "dlobj":{"address":"ABC","dlStatus":"valid","dob":"dd-MM-yyyy","father":" SAMPLE ","dlName":"JOHN","dlIssuedt":"dd-MM-yyyy","dlNtValdtoDt":" dd-MM-yyyy","dlNtValdfrDt":"dd-MM-yyyy ","status":"valid"},
      "status":"valid"
    }
}

现在我有一个代码,用于使用下面给出的代码将值存储在数据库中,我返回一些值并将其存储到数据库中

        if(dlApiResponse.has("dlCovs")){
        String dataDlcov_Obj = dlApiResponse.get("dlCovs").toString();
        Object json = new JSONTokener(dataDlcov_Obj).nextValue();
        if (json instanceof JSONObject) {
            JSONObject dlCovDataJson = (JSONObject)dlApiResponse.get("dlCovs");
            DrivingLicenceCOV dl_cov = new DrivingLicenceCOV(dl.getId(), dlCovDataJson);
            dl_cov.setCreatedAt(new Date());
            dlCOVService.save(dl_cov);
        }

    return dl;
}

这里dlApiResponse只是JSONObject,如上所述 现在当我执行这个代码块时,它不会进入给定的代码块,这限制了我将值放在数据库中。无论如何,他们使用哪些我可以遍历条件并将其存储在数据库中?任何帮助都会很明显,提前谢谢

0 个答案:

没有答案