java - 如何将嵌套 JSON 数组转换为 java 对象?

标签 java spring-boot spring-data-jpa

我收到一个嵌套 JSON 数组,我必须读取 JSON 并将其数据写入新文件中。

   "users": [
   {
      "user_id": "B781C132CAAC45CAB557F29FEA20C4BA",
      "$distinct_id": "C621631D24A6428589C8C94BAA18EA3B",
      "$properties": {
         "Platforms": "["web"]",
         "trial_class_flow": true,
         "Subscription Plan": null,
         "Autorenew Credit Card": "false",
         "Username": "midi31",
         "$email": "auto_test_368107_gaylene.turcotte@splashmath.com",
         "$first_name": "Player",
         "$last_name": null,
         "User Type": "student",
         "Paid": false,
         "Paid Once": false,
         "Created At": "2019-08-07T12:11:23Z",
         "Unsubscribe Id": "A87B13E627D24CE5BA660100E98F99D4",
         "First Platform": "web",
         "First App ShortCode": "",
         "Signup Flow": "trial_class_25",
         "School Name": "NA"
      }
   }
]

无法思考如何在 java 中对其进行建模。

最佳答案

有一个很好的在线实用程序可以为您完成此操作。将 JSON 粘贴到编辑器中,这将为您提供所需的 POJO。一旦获得 POJO,您就可以使用它来做任何您想做的事情。

根据记录,还有其他工具也可以执行相同的操作。我碰巧更经常使用这个,所以给出 URL。

看看这个:http://www.jsonschema2pojo.org/

关于java - 如何将嵌套 JSON 数组转换为 java 对象?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57407275/

相关文章:

java - 如何将自定义/默认值设置为来自数据库的值?

java - Spring数据存储库: "find" method with orderBy gets the wrong order

java - org.hibernate.MappingException : Could not determine type for custom object type

spring-boot - Spring-data-JPA - 执行复杂的多连接查询

java - 内部事务(REQUIRES_NEW)抛出异常时外部事务回滚

java - 子类型多态性 : Always late binding?

java - Java 中的对象数组冒泡排序

java - apache Camel 天气库入门

java - 将 ActiveRecord 数据模型逆向工程为 jpa

java - 根据输入执行 "pipeline"个用户定义操作的设计