将 json 转换为 dart 时遇到问题,下面是 json

Posted

技术标签:

【中文标题】将 json 转换为 dart 时遇到问题,下面是 json【英文标题】:I am facing issue when converting json to dart, below is the json 【发布时间】:2021-09-25 22:58:58 【问题描述】:

IN this you can find the error when json is converted当我使用 https://javiercbk.github.io/json_to_dart/ 将下面的 json 转换为 dart 时,它说“生成的 Dart 代码无效”。我正在使用未来的构建器在用户界面中显示响应。 当我注释掉“状态”类时,错误发生但没有显示响应。


      
                  "result": 
                      "userDetails": 
                          "digilockerid": "...digilockerid...",
                          "name": "...name...",
                          "dob": "...dob...",
                          "gender": "...M/F/T...",
                          "eaadhaar": "...Y or N as per availability..."
                      ,
                      "files": [
                          "name": "Aadhaar Card",
                          "type": "file",
                          "size": "",
                          "date": "...date...",
                          "parent": "",
                          "mime": [
                              "application/pdf",
                              "application/xml",
                              "application/json"
                          ],
                          "doctype": "...5 letter DOC key...",
                          "description": "...Description...",
                          "issuerid": "...issuer id...",
                          "issuer": "...issuer name...",
                          "id": "...unique file ID..."
                      ],
                      "eAadhaar": 
                          "name": "...name...",
                          "dob": "...date of birth...",
                          "uid":"...uid...",
                          "gender": "...gender...",
                          "x509Data": 
                              "validAadhaarDSC": "...is eaadhaar certificate valid or not (yes/no)..."
                          ,
                          "address": "...address",
                          "photo": "...link to photo as on eaadhaar...",
                          "splitAddress": 
                              "district": [
                                  "...district name..."
                              ],
                              "state": [
                                  [
                                      "...state name...",
                                      "...2 digit state code..."
                                  ]
                              ],
                              "city": [
                                  "...city name..."
                              ],
                              "pincode": "...pincode...",
                              "country": [
                                  "...2 digit ISO country name...",
                                  "...3 digit ISO country name...",
                                  "...country name..."
                              ],
                              "addressLine": "...address..."
                          
                      
                  
              

【问题讨论】:

您使用的是空安全吗? noo ,这与空安全无关。在线将json转换为对象时会出现此问题 【参考方案1】:

我不知道这是否适合你,但它有效,我改变了这个:

"state": [
      [
           "...state name...",
           "...2 digit state code..."
                                  ]
                              ]

到这里:

"state": [
             "...state name...",
             "...2 digit state code..."
             ]
                              

而且它没有显示无效的飞镖代码消息

【讨论】:

是的,错误消失了,bt im nt 得到响应 json

以上是关于将 json 转换为 dart 时遇到问题,下面是 json的主要内容,如果未能解决你的问题,请参考以下文章

如何将这个复杂的Json转换为Dart对象

将 json 结果转换为 dart 模型

如何将 JSON 字符串转换为数字?

我使用 JSON 转换器将 JSON 转换为 c# 时遇到问题

使用 python 将嵌套 json 转换为平面 json 时遇到困难

实现数据表时遇到错误-TypeError:将循环结构转换为 JSON