json - D10 到 DXE5 : what's the equivalent of TJSONBool. 创建(False)和 JSONObj.ToJSON?

标签 json delphi delphi-xe5

下面的代码在D10西雅图上编译得很好,但是我安装了D10的电脑坏了。然后我需要使用 DXE5 在我的项目中进行小更新,但无法编译,因为命令 TJSONBool.Create(False)JSONObj.ToJSON 存在。

DXE5上,什么相当于TJSONBool.Create(False)JSONObj.ToJSON

uses
 Data.DBXJSON, SHFolder;

function GetSpecialFolderPath(folder : integer) : string;
 const
   SHGFP_TYPE_CURRENT = 0;
 var
   path: array [0..MAX_PATH] of char;
 begin
   if SUCCEEDED(SHGetFolderPath(0,folder,0,SHGFP_TYPE_CURRENT,@path[0])) then
     Result := path
   else
     Result := '';
 end;

procedure ChangeChromeSetting(const ATarget, Avalue: string);
var
  specialfolder: integer;
  pathchrome: String;
  JSONObj, ObjIpp: TJSONObject;
  JSONPair: TJSONPair;
  OldValue: string;
begin
  specialFolder := CSIDL_LOCAL_APPDATA;
  pathchrome := GetSpecialFolderPath(specialFolder);
  pathchrome := pathchrome + '\Google\Chrome\User Data\Local State';

 if fileexists(pathchrome) then
  begin
    JSONObj := TJSONObject.ParseJSONValue(TFile.ReadAllText(pathchrome)) as TJSONObject;
    if not Assigned(JSONObj) then Exit; {raise Exception.Create('Cannot read file: ' + pathchrome);}
    try
      OldValue := JSONObj.GetValue<string>(ATarget);
       if OldValue = '' then
               Exit;
      if not SameText(OldValue, Avalue) then
      begin
        JSONPair := JSONObj.Get(ATarget);
        JSONPair.JsonValue.Free;
        JSONPair.JsonValue := TJSONString.Create(Avalue);

        ObjIpp := TJSONObject.Create;
        ObjIpp.AddPair('enabled', TJSONBool.Create(False));
        JSONObj.AddPair('hardware_acceleration_mode', ObjIpp);

        TFile.WriteAllText(pathchrome, JSONObj.ToJSON);
      end;
    finally
      JSONObj.Free;
    end;
  end;
end;

//////////////////////  USAGE /////////////////////////

ChangeChromeSetting('hardware_acceleration_mode_previous', 'false');

最佳答案

TJSONBoolTJSONAncestor.AsJSON 在 XE5 中尚不存在。 XE7 中添加了 ToJSON,10.0 Seattle 中添加了 TJSONBool

在旧版本中,使用 TJSONTrue/TJSONFalseTJSONObject.ToString相反:

ObjIpp.AddPair('enabled', TJSONFalse.Create);
... 
TFile.WriteAllText(pathchrome, JSONObj.ToString);

关于json - D10 到 DXE5 : what's the equivalent of TJSONBool. 创建(False)和 JSONObj.ToJSON?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47745697/

相关文章:

delphi - TResourceStream 的进度条 (Delphi)

delphi - Delphi中缩放 Canvas 区域

delphi - 为引用的命名空间创建别名

delphi - iOS应用程序名称带有单独的单词

delphi - 如何在Delphi中的Units初始化部分捕获异常

javascript - 使用$http服务,找不到数据

c# - PowerShell 二进制模块程序集依赖性错误

java - 使用 GSON 传递 jira json

Java/Javascript/JSON - 将 JSON 字符串从 Java 传递到 Javascript

delphi - 如果我不小心从控件引用的表单使用列表中删除某些内容,是否会产生任何有害影响?