使用QJSON解析数据:
JSon 字符串:
{"Code":1,"Msg":"",
"Data":[{"NetType":"电信","ServerName":"test1","ServerAddr":"127.0.0.1:30001","ServerIp":"55551","ServerPort":3000,"OnlineCount":300,"MaxOnlineCount":0},{"NetType":"电信","ServerName":"test1","ServerAddr":"::13000","ServerIp":"::1","ServerPort":3000,"OnlineCount":3,"MaxOnlineCount":0},{"NetType":"电信","ServerName":"test1","ServerAddr":"127.0.0.1:3000","ServerIp":"::1","ServerPort":3000,"OnlineCount":3,"MaxOnlineCount":0}]}
Delphi代码:
procedure TForm2.Button1Click(Sender: TObject); var Json,AItem:TQJson; i:Integer; begin Json:=TQJson.Create; Json.Parse(Memo1.Text); //ShowMessage(Json.AsString); AItem := Json.ItemByName('Data') ; for I := 0 to AItem.Count-1 do begin Memo2.Lines.Add(AItem.Items[i].ValueByName('NetType','')); Memo2.Lines.Add(AItem.Items[i].ValueByName('ServerAddr','')); Memo2.Lines.Add(AItem.Items[i].ValueByName('ServerIp','')); Memo2.Lines.Add(AItem.Items[i].ValueByName('ServerPort','')); Memo2.Lines.Add(AItem.Items[i].ValueByName('OnlineCount','')); Memo2.Lines.Add(AItem.Items[i].ValueByName('MaxOnlineCount','')); Memo2.Lines.Add('-----------------------------------------') end; end;
其它例子:
1.http://www.cnblogs.com/codingnote/p/3821025.html?utm_source=tuicool&utm_medium=referral