我有一个TDataSet的JSON助手的功能。
我想结果返回如下:
{"result":[{"rid":"2","firstname":"veli","lastname":"deli"},{"rid":"1","firstname":"ismail","lastname":"kocacan"}]}
But.Does不work.The返回以下内容:
{"result":[[{"rid":"2","firstname":"veli","lastname":"deli"},{"rid":"1","firstname":"ismail","lastname":"kocacan"}]]}
我想删除多余的[字符...
如何提取此数据并返回?
{"rid":"2","firstname":"veli","lastname":"deli"},{"rid":"1","firstname":"ismail","lastname":"kocacan"}
我TDataSet的JSON助手功能:
TDatasetJSONHelper = class helper for TDataset
public
function ToJSONData: TJSONArray;
function ToJSONDataWrapper: TJSONValue;
end;
function TDatasetJSONHelper.ToJSONData: TJSONArray;
var
jso: TJSONObject;
jsa: TJSONArray;
jsp: TJsonPair;
J: Integer;
avalue: TJSONValue;
begin
Self.Close;
Self.Open;
jsa := TJSONArray.Create();
while not Self.Eof do
begin
jso := TJSONObject.Create();
for J := 0 to FieldCount - 1 do
jso.AddPair(TJsonPair.Create(Fields[J].DisplayName, Fields[J].Value));
jsa.AddElement(jso);
Self.Next;
end;
Self.Close;
Result := jsa;
end;
function TDatasetJSONHelper.ToJSONDataWrapper: TJSONValue;
var
aJSON: TJSONObject;
apair: TJsonPair;
avalue: TJSONValue;
begin
aJSON := TJSONObject.ParseJSONValue
(TEncoding.ASCII.GetBytes
('{"result":[[{"rid":"2","firstname":"veli","lastname":"deli"},{"rid":"1","firstname":"ismail","lastname":"kocacan"}]]}'),
0) as TJSONObject;
apair := aJSON.Get(0);
avalue := apair.JsonValue;
// ??? avalue := '{"rid":"2","firstname":"veli","lastname":"deli"},{"rid":"1","firstname":"ismail","lastname":"kocacan"}';
Result := avalue;
end;
function TServerMethods1.GetPersonList: TJSONArray;
begin
Result := dm.AdoQuery1.ToJSONData;
end;
function TServerMethods1.GetPersonList2: TJSONValue;
begin
Result := dm.AdoQuery1.ToJSONDataWrapper;
end;
我怎么解决这个问题 ?