superobject.pas单元对json的解析非常方便, 力荐
下面演示对如下json的解析
{ "userid": "u0001", "info": [ { "url": "rtmp://192.168.3.159/livepkgr/66?adbe-live-event=liveevent", "lng": 105.97505, "lat": 34.271555, "id": "0001", "memo": "S.H.E 001" },{ "url": "rtmp://192.168.3.159/livepkgr/66?adbe-live-event=liveevent", "lng": 114.658574, "lat": 32.106045, "id": "0002", "memo": "S.H.E 002" },{ "url": "rtmp://192.168.3.159/livepkgr/66?adbe-live-event=liveevent", "lng": 112.818844, "lat": 26.563882, "id": "0003", "memo": "S.H.E 003" },{ "url": "rtmp://192.168.3.159/livepkgr/66?adbe-live-event=liveevent", "lng": 104.687239, "lat": 29.534077, "id": "0004", "memo": "S.H.E 004" }], "area": "sz01" }
procedure TForm1.btn1Click(Sender: TObject); var s:String; i: Integer; jfields,jitems,jo:ISuperObject; begin jitems:=SA([]); jo:=SO(); jo.S[‘area‘] := ‘sz01‘; jo.S[‘userid‘] := ‘u0001‘; for i := 0 to 3 do begin jfields:=SO(); jfields.S[‘id‘]:= Format(‘%.4d‘, [i+1]); jfields.D[‘lng‘]:= 102.0909; jfields.D[‘lat‘]:= 33.9888; jfields.S[‘url‘]:=‘rtmp://192.168.3.159/livepkgr/66?adbe-live-event=liveevent‘; jfields.S[‘memo‘]:=‘S.H.E 00‘+ IntToStr(i+1); jitems.AsArray.Add(jfields); end; jo.O[‘info‘]:=jitems; s := jo.AsJSon(True, False); mmo1.Text := s; end; procedure TForm1.btn2Click(Sender: TObject); var jo,m:ISuperobject; i,j:Integer; tt:TSuperArray; s:string; lst:TStringList; begin if mmo1.Text <>‘‘ then begin lst:=TStringList.Create; jo:=so(mmo1.Text); tt:=jo.O[‘info‘].AsArray; for i:=0 to tt.Length-1 do begin s:=tt.O[i].S[‘id‘]; lst.Add(s); end; ShowMessage(lst.Text) ; lst.Free; end; end;
点此下载该单元文件
时间: 2024-10-28 01:03:13