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 ...
随机推荐
- html学习-css
1.css初识 css 中文解释:层叠样式表,把html比作骨骼的话,css就是衣服,他的外在都能通过css来修饰,js则是肌肉,能使html动起来.产生用户交互... 1.1css样式表类型 css ...
- python正则表达式教程
原文这里,非常实用,转载一下 再来一篇,两篇一起看,美滋滋 本文介绍了Python对于正则表达式的支持,包括正则表达式基础以及Python正则表达式标准库的完整介绍及使用示例.本文的内容不包括如何编写 ...
- Templated Helper Methods
1.Model 2.HomeController 3.CreatePerson.cshtml 禁用了客户端验证 4.Using Templated Helper Methods Editor 和 Ed ...
- 原生js将数组分割成固定个数一组的小数组
reSetData(dataList,num) { let arr = []; let len = dataList.length; for (let i = 0; i < len; i += ...
- 牛客练习赛19 C-托米航空公司
思路:轮廓线dp,找bug找死我了. #include<bits/stdc++.h> #define LL long long #define fi first #define se se ...
- 创建数据模型(View Models )和监控属性(Observables)
Knockout是建立在以下3个核心功能之上的: 1. 属性监控与依赖跟踪 2. 声明式绑定 3. 模版机制 在本节中,我们将学习3个核心里面的第一个.但在这之前,先让我们学习一下MVVM设计模式和V ...
- thinkjs项目中使用mongoose需要注意的地方
原文链接thinkjs项目中使用mongoose需要注意的地方 由于thinkjs不支持mongodb的关联模型查询,所以我不得不使用mongoose这个第三方odm. 我有两个选择,一是像我在exp ...
- 洛谷P1073 最优贸易 [图论,DP]
题目传送门 最优贸易 题目描述 C 国有n 个大城市和m 条道路,每条道路连接这n 个城市中的某两个城市.任意两个城市之间最多只有一条道路直接相连.这m 条道路中有一部分为单向通行的道路,一部分为双向 ...
- Python并发编程-线程-一个简单的例子
from threading import Thread import time def func(n): #子线程完成的 time.sleep(1) print(n) #多线程示例 for i in ...
- Docker运行oracle12c注意事项
title: docker运行oracle12c注意事项 date: 2019-03-27 13:42:34 categories: 数据库 author: mrzhou tags: docker 数 ...