zoukankan      html  css  js  c++  java
  • JSON代码示例

    生成JSON:

    var
      json: ISuperObject;
      i: Integer;
      jsonList, jsonRow: ISuperObject;
    begin
      json := SO();
      jsonList := SO('[]');
      try
        try
          for I := 0 to EventList.Count - 1 do
          begin
            jsonRow := SO('{}');
            jsonRow.S['strGUID'] := EventList[I].strEventID;
            jsonRow.S['strCaption'] := EventList[i].EventProperty.GetEventTypeName; 
            jsonRow.I['nTriggerLC'] := EventList[i].nTriggerGLB;
            jsonRow.I['nSectionBeginLC'] := EventList[i].nSectionBeginGLB;
            jsonRoW.I['nSectionEndLC'] := EventList[i].nSectionEndGLB;
            jsonList.AsArray.Add(jsonRow);    
          end;
          
          json.I['cmdtype'] := ord(esuctNew);
          json.O['EventList'] := jsonList;
          m_IdUDPClient.Send(json.AsString);
    
        except
          on e: Exception do
          begin
            AddLog('新的演练命令错误:' + e.Message);
          end;
        end;
      finally
        json := nil;
      end;
    

    解析JSON:

    var
      dd: TSuperArray;
      i: Integer;
      Eventobj: TQuestionEvent;
      json: ISuperObject;
    begin
      json := SO(strMsg);
      try
        cmdType :=json.I['cmdtype']; 
        dd := json.O['EventList'].AsArray;
        for I := 0 to dd.Length - 1 do
        begin
          EventObj := TQuestionEvent.Create; 
          Eventobj.strEventID := dd[i].S['strGUID'];
          Eventobj.strOptHint := dd[i].S['strCaption'];
          Eventobj.nTriggerGLB := dd[i].I['nTriggerLC'];
          Eventobj.nSectionBeginGLB := dd[i].I['nSectionBeginLC']; 
          Eventobj.nSectionEndGLB := dd[i].I['nSectionEndLC'];
        
          EventList.Add(Eventobj);
        end;
      finally
          
      end;     
    

      

  • 相关阅读:
    css学习笔记1
    HTML学习笔记4
    Layui使用入门教程
    MVC _Layout
    C# MVC _viewstart.cshtml的作用
    用javascript提交表单
    form表单中的属性和标签
    <input>标签中id和name的作用和区别
    input type = button 的onclick属性调用函数
    form表单提交onclick和onsubmit
  • 原文地址:https://www.cnblogs.com/tsolarboy/p/9472540.html
Copyright © 2011-2022 走看看