使用superobject 新建Json数据(数组)

1. 要得到的Json数据:[{"name":"张三","age": 17},{"name":"李四","age":20}]

 1 function GetArrayJson: string;
 2 
 3   function GetPersonSO(const AName: string; AAge: Integer): ISuperObject;
 4   begin
 5     Result := SO;
 6     Result.S['name'] := AName;
 7     Result.I['age'] := AAge;
 8   end;
 9 
10 var
11   vJa: ISuperObject;
12 begin
13   vJa := SA([]);
14   vJa.AsArray.Add(GetPersonSO('张三', 17));
15   vJa.AsArray.Add(GetPersonSO('李四', 20));
16   Result := vJa.AsJson;17 end;

2. 要得到的Json数据:{“data”:[{"name":"张三","age": 17},{"name":"李四","age":20}]}

function GetDataJson: string;

  function GetPersonSO(const AName: string; AAge: Integer): ISuperObject;
  begin
    Result := SO;
    Result.S['name'] := AName;
    Result.S['age'] := AAge;
  end;

  function GetArraySO: ISuperObject;
  begin
    Result := SA([]);
    Result.AsArray.Add(GetPerson('张三', 17));
    Result.AsArray.Add(GetPerson('李四', 20))
  end;

var
  vJo: ISuperObject;
begin
  vJo := SO;
  vJo.O['data'] := GetArraySO;
  Result := vJo.AsJson;
end;
原文地址:https://www.cnblogs.com/CinYung/p/8119322.html