Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function TGraphQLJson.ASTValueToJSON(Value: TASTValue): TJsonValue;
- var
- I: Integer;
- begin
- Result := nil;
- try
- if Value is TASTListValue then
- begin
- Result := TJsonArray.Create;
- for I := 0 to TASTListValue(Value).Count - 1 do
- TJsonArray(Result).AddElement(ASTValueToJSON(TASTListValue(Value).Items[I]));
- end;
- if Value is TASTObjectValue then
- begin
- Result := TJsonObject.Create;
- for I := 0 to TASTObjectValue(Value).Count - 1 do
- TJsonObject(Result).AddPair(TASTObjectValue(Value).Items[I].Name, ASTValueToJSON(TASTObjectValue(Value).Items[I].Value));
- end;
- if Value is TASTStringValue then
- Result := TJsonString.Create(TASTStringValue(Value).Value);
- if Value is TASTIntValue then
- Result := TJsonNumber.Create(TASTIntValue(Value).Value);
- if Value is TASTNullValue then
- Result := TJsonString.Create;
- if Value is TASTBooleanValue then
- Result := TJsonBool.Create(TASTBooleanValue(Value).Value <> 'false');
- if Value is TASTFloatValue then
- Result := TJsonNumber.Create(TASTFloatValue(Value).Value);
- except
- Result.Free;
- raise;
- end;
- end;
- constructor TGraphQLJson.Create;
- begin
- inherited Create('JSON');
- end;
- function TGraphQLJson.ParseLiteral(Value: TASTValue): TValue;
- var
- JsonValue: TJsonValue;
- begin
- JsonValue := ASTValueToJSON(Value);
- Result := TValue.From<TJsonValue>(JsonValue);
- end;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement