delphi生成JSON格式字符串的一个简单的类
unit JsonUtilUnt;
interface
type
TJSONTokener = class(TObject)
private
jsonStr:WideString;
public
constructor Create;
destructor destroy;override;
procedure AddElement(nodeName,nodeValue:String);
procedure ClearElement;
function toString:WideString;
end;
implementation
{ TJSONTokener }
constructor TJSONTokener.Create;
begin
inherited;
end;
destructor TJSONTokener.destroy;
begin
inherited;
end;
procedure TJSONTokener.AddElement(nodeName,nodeValue:String);
begin
if length(jsonStr)>0 then
jsonStr:=ConCat(jsonStr,',"',nodeName,'":',nodeValue)
else
jsonStr:=ConCat(jsonStr,'"',nodeName,'":',nodeValue);
end;
procedure TJSONTokener.ClearElement;
begin
jsonStr:='';
end;
function TJSONTokener.toString:WideString;
begin
Result:=ConCat('{',jsonStr,'}');
end;
end.
更多推荐
所有评论(0)