使用GSON解析复杂的JSON

时间:2018-05-30 19:44:04

标签: android json parsing gson

我想知道什么是解析这个JSON的最有效方法

   [  
   {  
      "name":"heading-1",
      "value":"Heading",
      "type":"heading",
      "css":"",
      "helpText":"",
      "size":"Small",
      "displayLogic":{  
         "type":"show",
         "rules":{  

         }
      },
      "guid":"fb39e01c-2802-461f-984a-b76aeb6bed33"
   },
   {  
      "name":"text-1",
      "label":"Equipment name",
      "value":"",
      "placeholder":"Enter Text here ...",
      "type":"text",
      "css":"",
      "helpText":"",
      "validations":[  
         {  
            "type":"required",
            "details":{  
               "active":false,
               "message":"Required!",
               "values":{  

               }
            }
         },
         {  
            "type":"minlength",
            "details":{  
               "active":false,
               "message":"Please enter more text!",
               "values":{  
                  "min":"3"
               }
            }
         },
         {  
            "type":"maxlength",
            "details":{  
               "active":false,
               "message":"Your response was too long!",
               "values":{  
                  "max":"7"
               }
            }
         }
      ],
      "dataGridColumnInfo":{  
         "position":"1",
         "heading":"New Text Box",
         "displayType":"text",
         "actionType":"view"
      },
      "displayLogic":{  
         "type":"show",
         "rules":{  

         }
      },
      "guid":"8a58826e-7957-4f2c-8ea7-acebf624ac25"
   }
]

这只是我的JSON的片段,因为整个事情都很长。但是你可以看出,它有点复杂。我正在使用GSON进行解析,我不确定是否应该为每个对象创建一个类,或者我是否应该手动执行它。我还需要能够编辑json并将其写入文件。有什么建议吗?

1 个答案:

答案 0 :(得分:0)

使用http://www.jsonschema2pojo.org。它将解析你的json并创建所有必需的类

相关问题