例子:
组Json串:
procedure TForm8.Button4Click(Sender: TObject);
var
i: Integer;
jfields, jitems, jo: ISuperObject;
begin
Memo1.Clear;
jitems := SA([]);
jo := SO();
with ADOQuery1 do
begin
First;
while not eof do
begin
jfields := SO();
for i := to FieldCount - do
begin
jfields.S['Addr'] := FieldByName('Addr').Value;
jfields.S['Factory'] := FieldByName('Factory').Value;
end;
jitems.AsArray.Add(jfields);
Next;
end;
end;
jo.S[''] := '';
jo.S[''] := '';
jo.S[''] := '';
jo.S[''] := '';
jo.O['records'] := jitems; Memo1.Lines.Add(jo.AsString);
end;
组装好以后图:
拆分Json:
mmo1.Text := '{"code":268435457,"message":"记录异常","data":{"savedCount":0,"faildItems":[{"ReasonUNRead":0}]}}';
1、ShowMessage(jo.O['message'].AsString);
st:=jo['data'].O['faildItems'].AsArray;
for I := 0 to st.Length - 1 do
begin
s:='';
s := s+' '+st.O[i].AsString;
Memo1.Lines.Add(s);
end;
拆分后的图: