Json解析
1 //JSON解析 2 function TForm5.JsonResolve(sStr:string):string; 3 var 4 jSOObj:ISuperObject; 5 jOObj:ISuperObject; 6 jRoot,jSid:ISuperObject; 7 sRoot,sSid:string; 8 arrayStr:TSuperArray; 9 i:Integer; 10 begin 11 jSOObj := SO(sStr); 12 jOObj := jSOObj.O['Class']; 13 if jOObj <> nil then 14 begin 15 sRoot := jSOObj.O['Class'].AsString; 16 jOObj := SO(sRoot); 17 sSid := jOObj.O['StudentName'].AsString; 18 jSid := SO(sSid); 19 arrayStr := jSid.AsArray; 20 for I := 0 to arrayStr.Length - 1 do 21 begin 22 MeterData := TMeterData.Create; 23 MeterData.sName := arrayStr[i].O['Name'].AsString; 24 MeterData.sSex := arrayStr[i].O['Sex'].AsString; 25 memo1.Lines.Add(MeterData.sName); 26 end; 27 end; 28 end;
测试数据: sStr := '{"Class":{"StudentName":[{"Name":"Json","Sex":"G"}]}}'; JsonResolve(sStr);