JSON-C结构介绍、使用

官方网站介绍http://www.json.org

JSON (JavaScript Object Notation) is a lightweight data-interchange format. It is easy for humans to read and write. It is easy for machines to parse and generate. It is based on a subset of the JavaScript Programming LanguageStandard ECMA-262 3rd Edition - December 1999. JSON is a text format that is completely language  independent but uses conventions that are familiar to programmers of the C-family of languages, including C, C++, C#, Java, JavaScript, Perl, Python, and many others. These properties make JSON an ideal data-interchange language.



JSON结构体如下:

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
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;
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值