简体   繁体   English

使用GSON解析复杂的JSON

[英]Parsing complex JSON using GSON

I was wondering what would be the most effective way to parse this JSON 我想知道解析此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"
   }
]

This is just a snippet of my JSON, as the whole thing is pretty long. 这只是我的JSON的摘要,因为整个过程很长。 As you can tell though, it gets a little complicated. 如您所知,它有点复杂。 I'm using GSON to parse, and I am not sure if I should have a class for each object, or if I should just do it manually. 我正在使用GSON进行解析,并且不确定是否应该为每个对象都有一个类,还是应该手动进行处理。 I also need to be able to edit the json and write it to a file. 我还需要能够编辑json并将其写入文件。 Any suggestions? 有什么建议么?

use http://www.jsonschema2pojo.org . 使用http://www.jsonschema2pojo.org It will parse your json and create all the required classes 它将解析您的json并创建所有必需的类

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM