JSON还原为结构体
JSON还原为结构体
1)JSON字符串还原为结构体;
2)访问结构体的字段值;
本例运行效果图:

uses
SynCommons;
const // JSON字符串
JSON1 =
'{' + #13#10 + '"glossary": {' + #13#10 + '"title": "中国",' + #13#10
+ ' "GlossDiv": {' + #13#10
+ '"title": "湖南省",' + #13#10
+ ' "GlossList": {' + #13#10
+ '"GlossEntry": {' + #13#10
+ '"ID": "湘乡市",' + #13#10
+ ' "SortAs": "SGML",' + #13#10
+ ' "GlossTerm": "Standard Generalized Markup Language",' + #13#10
+ ' "Acronym": "SGML",' + #13#10
+ ' "Abbrev": "ISO 8879:1986",' + #13#10
+ ' "GlossDef": {' + #13#10
+ '"para": "A meta-markup language, used to create markup languages such as DocBook.",' + #13#10
+ ' "GlossSeeAlso": ["咏南中间件", "XML"]' + #13#10
+ '},' + #13#10
+ ' "GlossSee": "markup"' + #13#10 + '}'
+ #13#10 + '}' + #13#10
+ '}' + #13#10
+ '}' + #13#10
+ '}';
type // 记录
TGlossary = record
glossary: record
title: string;
GlossDiv: record
title: string;
GlossList: record
GlossEntry: record
ID, SortAs, GlossTerm, Acronym, Abbrev: string;
GlossDef: record
para: string;
GlossSeeAlso: array of string;
end;
GlossSee: string;
end;
end;
end;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
gloss: TGlossary;
json: RawUTF8;
begin
json := JSON1;
RecordLoadJSON(gloss, @json[1], TypeInfo(TGlossary));
Memo1.Clear;
Memo1.Lines.Add(gloss.glossary.title); // 中国
Memo1.Lines.Add(gloss.glossary.GlossDiv.title); // 湖南省
Memo1.Lines.Add(gloss.glossary.GlossDiv.GlossList.GlossEntry.ID); // 湘乡市
Memo1.Lines.Add(gloss.glossary.GlossDiv.GlossList.GlossEntry.GlossDef.GlossSeeAlso[0]); // 咏南中间件
end;
JSON还原为结构体的更多相关文章
- XmlRpc.net 出参字符串还原为结构体
上一篇随笔写的是入参结构体转字符串,现在需要把保存到服务器的字符串还原为结构体,这里记录一下操作步骤: 1. 格式化字符串. XmlRpcDeserializer 支持反序列化<struct&g ...
- go语言之进阶篇json解析到结构体
1.json解析到结构体 示例: package main import ( "encoding/json" "fmt" ) type IT struct { ...
- [GO]json解析到结构体
package main import ( "encoding/json" "fmt" ) type IT struct { Company string `j ...
- Delphi 10.2 JSON与对象/结构体序列化性能提高100多倍
今天在盒子闲逛,无意中看到有人说XE7自带的Json对象序列化很慢,帖子在这里:http://bbs.2ccc.com/topic.asp?topicid=464378;经过测试的确如此. 但 ...
- go get请求 json字符串转为结构体
package main import ( "io/ioutil" "fmt" "net/http" "encoding/json ...
- json数据转换成结构体
package main import ( "encoding/json" "fmt" ) type IT1 struct { Company string ` ...
- 在线JSON转Go 结构体,在线JSON转Go Struct
在线转换https://oktools.net/json2go
- 结构体序列为JSON
结构体序列为JSON 本例运行效果图: uses SynCommons; const /// JSON字符串 JSON1 = '{' + #13#10 + '"glossary": ...
- Golang操作结构体、Map转化为JSON
结构体生成Json package main import ( "encoding/json" "fmt" ) type IT struct { Company ...
随机推荐
- java中常见异常汇总(根据自己遇到的异常不定时更新)
1.java.lang.ArrayIndexOutOfBoundsException:N(数组索引越界异常.如果访问数组元素时指定的索引值小于0,或者大于等于数组的长度,编译程序不会出现任何错误,但运 ...
- 阻止MyEclipse启动项目时自动跳转的debug视图
启动web项目时,习惯使用debug方式启动,但此时会自动跳转到debug视图,很不习惯. 通过修改首选项配置,可以禁止跳转
- 创建 dblink
目的:oracle中跨数据库查询 两台数据库服务器db_A(本地)和db_B(远程192.168.1.100),db_A下用户user_a 需要访问到db_B下user_b的数据解决:查询 ...
- 深度学习方法(九):自然语言处理中的Attention Model注意力模型
欢迎转载,转载请注明:本文出自Bin的专栏blog.csdn.NET/xbinworld. 技术交流QQ群:433250724,欢迎对算法.技术感兴趣的同学加入. 上一篇博文深度学习方法(八):Enc ...
- AC日记——825G - Tree Queries
825G - Tree Queries 思路: 神题,路径拆成半链: 代码: #include <cstdio> #include <cstring> #include < ...
- 使用递归计算n的阶乘n!
计算n! 观察公式2可以直接使用递归求解 C++代码如下: #include <iostream> using namespace std; unsigned func(unsigned ...
- Wannafly挑战赛18 C - 异或和
思路:我刚开始是想旋转四次坐标,每次用bit计算每个点左上角的点到这个点的距离,TLE了.... 这种算曼哈顿距离的可以将x 轴和 y 轴独立开来,分别计算. #include<bits/std ...
- 在linux下安装sbt
1.到官方网站下载deb包,下载地址:https://dl.bintray.com/sbt/debian/sbt-1.0.3.deb 2.点击下载的deb包进行安装 3.安装完成后,在terminal ...
- vue表格导出
inportexcel: function() { //兼容ie10哦! require.ensure([], () => { const { export_json_to_excel } = ...
- CodeForces 803A Maximal Binary Matrix
枚举. 枚举对角线上放多少个$1$,剩余的贪心放,更新答案. #include <iostream> #include <cstdio> #include <cstrin ...