• 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;     
    

      

  • 相关阅读:
    服务管理命令
    软件管理
    Qt软件打包与发布(windeployqt工具)
    03
    第一章 BP神经网络
    代理模式 与 Spring AOP
    java 回调机制
    HashTable 实现
    实现Singleton模式
    BST 汇总
  • 原文地址:https://www.cnblogs.com/tsolarboy/p/9472540.html
Copyright © 2020-2023  润新知