c - 如何在c中以优雅的方式将json转换为struct
问题描述
有一个json和一个结构:
json:
{
"zone":12
"id":1
"rule":8
"name":"jsontest"
}
结构:
strict foo
{
int Zone;
int Id;
uint8_t Rule;
char Name[32];
}
我创建了一个映射来将 json 转换为 struct:
map[]
{
/* label key func*/
{Zone, "zone", JsonSafeGetInt},
{Rule, "rule", JsonSafeGetInt},
{Id, "id", JsonSafeGetInt},
{Name, "name", JsonSafeGetString}
}
我想使用地图将 json 转换为 struct:
strict foo *fooPtr;
for (i = 0; i< MapSize; i++)
{
fooPtr->map[i].label = map[i].func(xxx);
}
但是我不知道它是否可以实现,因为我不知道如何用C编写这样的代码。
解决方案
推荐阅读
- servicenow - 开发服务门户应用程序的架构建议
- angular - 将 css-element-queries 导入 Angular 6 应用程序
- node.js - 为什么“npm install”会修改 package-lock.json?那为什么要把它提交给git呢?
- android - 从片段调用 Intent 时出错(用户登录)
- angular - 如何从订阅中设置全局变量的值
- compiler-construction - 如果在使用 Hop-croft 算法最小化确定性有限自动机中接受所有状态怎么办?
- python-3.x - pip 已安装但不在 /usr/bin 中
- php - Laravel - 获取 1m+ 行并传递给 vueJS
- json - Spring REST服务响应编码问题
- java - 哪个版本的 Java 支持 -command 选项?