【店小二】公告:

json转proto
9753  |   |   |  27

功能介绍

1.支持解析嵌套 json 串, 根据递归进行解析嵌套对象
2.支持解析数组 json 串, 会取数组中第一个 json 串进行解析
3.检查 json 串格式是否正确, 输出错误的位置

示例

解析嵌套 json 串

{
    "name": "test",
    "age": 10,
    "addr": "四川成都",
    "cls_info": [
        {
            "name": "篮球班",
            "teacher": "张老师"
        },
        {
            "name": "美术班",
            "teacher": "李老师"
        }
    ]
}

处理后

message GenerateObj {
  string name = 1;
  int32 age = 2;
  string addr = 3;
  repeated ClsInfo cls_info = 4;
}

message ClsInfo {
  string name = 1;
  string teacher = 2;
}

直接解析数组 json 串

[
    {
        "name": "test",
        "age": 10,
        "addr": "四川成都",
        "cls_info": [
            {
                "name": "篮球班",
                "teacher": "张老师"
            },
            {
                "name": "美术班",
                "teacher": "李老师"
            }
        ]
    },
    {
        "name": "test2",
        "age": 10,
        "addr": "四川成都",
        "cls_info": [
            {
                "name": "篮球班",
                "teacher": "张老师"
            },
            {
                "name": "美术班",
                "teacher": "李老师"
            }
        ]
    }
]

处理后

message GenerateObj {
  string name = 1;
  int32 age = 2;
  string addr = 3;
  repeated ClsInfo cls_info = 4;
}

message ClsInfo {
  string name = 1;
  string teacher = 2;
}