【店小二】公告:
json轉proto
| | |
功能介紹
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;
}