nixzhu / Baby

Create models from a JSON file, even a Baby can do it.
https://apps.apple.com/cn/app/ducky-model-editor/id1525505933
MIT License
222 stars 21 forks source link

这种嵌套的 JSON 无法生成正确的 Model 吗? #6

Closed angelen10 closed 7 years ago

angelen10 commented 7 years ago

服务端返回的 JSON 如下:

{
  "code": 200,
  "msg": "ok",
  "data": {
    "list": [
      {
        "id": 1,
        "pid": 0,
        "code": 110000,
        "name": "北京市"
      },
      {
        "id": 8040,
        "pid": 5630,
        "code": 1093,
        "name": "崖城镇"
      },
      {
        "id": 8041,
        "pid": 5630,
        "code": 1094,
        "name": "育才镇"
      },
      {
        "id": 8064,
        "pid": 8050,
        "code": 1117,
        "name": "陵水黎族自治县"
      },
      {
        "id": 8065,
        "pid": 8050,
        "code": 1118,
        "name": "保亭黎族苗族自治县"
      },
      {
        "id": 8066,
        "pid": 8050,
        "code": 1119,
        "name": "琼中黎族苗族自治县"
      },
      {
        "id": 8067,
        "pid": 5939,
        "code": 1120,
        "name": "经开区"
      },
      {
        "id": 8081,
        "pid": 8077,
        "code": 1134,
        "name": "五家渠市"
      }
    ]
  }
}

错误如下: 图片

nixzhu commented 7 years ago

Thanks for your test! I’ll investigate it later.

nixzhu commented 7 years ago

It’s a bug cause by an optimization for list.

For a temporary solution, you can change the list to list_ in JSON, after the generation, you change the model name back.

I’ll fix it in a new release.

angelen10 commented 7 years ago

Thank you for that. 😁

nixzhu commented 7 years ago

You can also use Array Object Map such as list: Info to avoid this issue.

angelen10 commented 7 years ago

@nixzhu Thanks for your advice.