【问题标题】:How to create nested json file based on user inputs?如何根据用户输入创建嵌套的 json 文件?
【发布时间】:2019-11-13 17:55:53
【问题描述】:

我们正在开发产品。请看下文。 这里左侧面板上的每个实体都是 mongo db 中的一个集合。用户完成填写所有表单详细信息后,需要创建一个带有键值对的 json 文件。这可以嵌套到任何级别。一个 rootMenuItem 可以有多个 MenuItem。一个 menuItem 可以有多个子项。等等。

这是用 Angular Js 开发的 UI 页面。每个集合说rootmenuItemmenuItem等都会有保存按钮来保存键值对

{
  "version": "19.22.02",
  "constants": {},
  "gui": {
    "screenSaver": {
      "imageId": "ACU_screensaver/MBAC_black"
    },
    "menu": [
      {
        "configId": "test",
        "tets": "RootMenuItem",
        "icon": {
          "imageId": "teste"
        },
        "primaryLabel": {
          "rawText": "test",
          "textId": "tese.0216"
        },
        "intro": {
          "imageLayers": [
            {
              "imageId": "test"
            }
          ]
        },
        "children": [
          {
            "widgetType": "test",
            "configId": "21e88e",
            "children": [
              {
                "widgetType": "Tile",
                "primaryLabel": {
                  "textId": "test",
                  "rawText": "test"
                },
                "secondaryLabel": {
                  "bindingType": "test",
                  "deviceId": "test",
                  "serviceId": 1,
                  "serviceType": 40,
                  "ifTrue": {
                    "textId": "test",
                    "rawText": "An"
                  },
                  "ifFalse": {
                    "textId": "acu1.0236",

多个用户可以创建和下载这个json文件

我们正在使用带有 mongodb 的 java spring boot 微服务

这里的问题是如何从这些数据中创建一个 json 文件。请同时检查示例 json。更快地生成 json 并将文件存储在 mongo db 上的最佳策略是什么。

【问题讨论】:

  • 你试过jacksonjson-parser吗?

标签: java spring mongodb rest spring-boot


【解决方案1】:
  1. 首先,我们需要一个可以将 json 映射到的 java 对象。
  2. 然后使用GSON我们可以将对象转换为字符串。
  3. 然后可以使用 Gson fileWriter 将 String json 写入文件。

这是一个例子: Write Json to file

让我知道:)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-10-22
    • 1970-01-01
    • 2017-12-08
    • 2020-08-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-11-18
    相关资源
    最近更新 更多