例子:
组Json串:
1 procedure TForm8.Button4Click(Sender: TObject); 2 var 3 i: Integer; 4 jfields, jitems, jo: ISuperObject; 5 begin 6 Memo1.Clear; 7 jitems := SA([]); 8 jo := SO(); 9 with ADOQuery1 do 10 begin 11 First; 12 while not eof do 13 begin 14 jfields := SO(); 15 for i := 0 to FieldCount - 1 do 16 begin 17 jfields.S['Addr'] := FieldByName('Addr').Value; 18 jfields.S['Factory'] := FieldByName('Factory').Value; 19 end; 20 jitems.AsArray.Add(jfields); 21 Next; 22 end; 23 end; 24 jo.S['1111111'] := '11111'; 25 jo.S['22222'] := '22222'; 26 jo.S['33333'] := '33333'; 27 jo.S['444444'] := '444444'; 28 jo.O['records'] := jitems; 29 30 Memo1.Lines.Add(jo.AsString); 31 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;
拆分后的图: