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;     
    

      

  • 相关阅读:
    ios字符串截取/数据存入数组
    ios字典用字符串输出
    ios身份证key字典排序
    java之接口
    Objective Runtime总结
    iOS GCD 详解
    设计模式和应用场景
    内存管理
    core data
    iOS 开发者证书总结 in-house
  • 原文地址:https://www.cnblogs.com/tsolarboy/p/9472540.html
Copyright © 2011-2022 走看看