Delphi 10.3 读取JSON数据
usesSystem.Types,
System.JSON,
System.JSON.Types,
System.JSON.Writers,
System.JSON.Builders;
procedure TForm1.Button4Click(Sender: TObject);
var
I: Integer;
m_JsonStr: string;
m_SubArray: TJSONArray;
m_JsonObject: TJSONObject;
m_SubJsonObj: TJSONObject;
begin
// 读取JSON文件
m_JsonStr := Trim(Memo1.Text);
m_JsonObject := TJSONObject.ParseJSONValue(TEncoding.UTF8.GetBytes(m_JsonStr), 0) as TJSONObject;
// 取最外层
for I := 0 to m_JsonObject.count - 1 do
begin
Memo2.Lines.Add(m_JsonObject.Get(I).JsonString.toString + ' = ' + m_JsonObject.Get(I).JsonValue.ToString);
end;
// 取内层
m_SubArray := m_JsonObject.getValue('五班') as TJSONArray;
for I := 0 to m_SubArray.size - 1 do
begin
m_SubJsonObj := m_SubArray.Get(I) as TJSONObject;
Memo2.Lines.Add(Format('标签:%s = %s', ));
Memo2.Lines.Add(Format('标签:%s = %s', ));
end;
end;
页:
[1]