superobject版本为1.2
开发环境D7
太容易忘记了,做个笔记
//1. Json的数组添加和赋值
1 var 2 Ijson,Ijson_01:ISuperObject; 3 s:string; 4 i:Integer; 5 begin 6 Ijson:=superobject.SO('{}'); 7 Ijson.S['Set01']:='0000'; 8 Ijson.S['Set02']:='1111'; 9 Ijson.s['WhereSQLSet']:='WHere sdghfgj=sdfjhdf'; 10 Ijson['WhereSQLSetDisplay']:=superobject.SA([]); 11 Ijson_01:=superobject.SO('{}'); 12 for i:=1 to 10 do 13 begin 14 Ijson_01.S['ID']:=IntToStr(i); 15 Ijson_01.S['Name']:='A_'+IntToStr(i); 16 Ijson.A['WhereSQLSetDisplay'].Add(Ijson_01); 17 end; 18 Memo3.Text:=Ijson.AsString; 19 end;
//2. 数组中套数组
1 var 2 Ijson,Json_array:ISuperObject; 3 s:string; 4 i:Integer; 5 begin 6 Ijson:=superobject.SO('{}'); 7 Ijson.S['Set01']:='0000'; 8 Ijson.S['Set02']:='1111'; 9 Ijson.s['WhereSQLSet']:='WHere sdghfgj=sdfjhdf'; 10 Ijson['WhereSQLSetDisplay']:=superobject.SA([]); 11 //Ijson_01:=superobject.SO('{}'); 12 Memo3.Clear; 13 for i:=1 to 10 do 14 begin 15 Json_array:= superobject.SA([]); 16 Json_array.AsArray.S[0] :=IntToStr(i); 17 Json_array.AsArray.S[1] :='A_'+IntToStr(i); 18 Ijson.A['WhereSQLSetDisplay'].Add(Json_array); 19 20 end; 21 Memo3.Text:=Ijson.AsString; 22 end;
//3.读取2中的Memo3的数组值
1 var 2 Ijson,Ijson_array:ISuperObject; 3 vs:string; 4 i:Integer; 5 begin 6 Ijson:=superobject.SO(Memo3.Text); 7 //读数组 8 vs:=''; 9 Memo4.Clear; 10 for i:=0 to 9 do 11 begin 12 Ijson_array:=superobject.SO(Ijson['WhereSQLSetDisplay'].AsArray.s[i]); 13 vs:=Ijson_array.AsArray.s[0]+';'+ 14 Ijson_array.AsArray.S[1]; 15 memo4.Lines.Add(vs); 16 end; 17 end;
//4.读取这个[{"name":"A000000","teacher":"Tea000000","classroom":"C_R000000"},{"name":"A000001","teacher":"Tea000001","classroom":"C_R000001"}]
只提供思路,代码片段,一种写法
1 jo := SO(str); 2 3 4 for i:=0 to jo.AsArray.Length-1 do //jo.AsArray.Length-1 5 begin 6 Append; 7 FieldByName('name').Value := jo.AsArray[i]['name'].AsString; 8 FieldByName('teacher').Value :=jo.AsArray[i]['teacher'].AsString; 9 FieldByName('classroom').Value :=jo.AsArray[i]['classroom'].AsString; 10 11 end;