- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用 Delphi Xe5,并且我有一个组件,该组件本质上使用 IDTCPCLient(套接字)与服务器通信并以 JSON 形式检索数据。我已经为您省去了所有连接代码等。它可以工作。返回的 JSon 也可以工作。我遇到的问题是将 JSON 转换为 StringList,然后使用它将值列表写入列表框并将其余 JSON 数据对象存储在 TSTrings OBjects 属性中。
我发生了很多有趣的事情。
1.) 我一生都无法让 List 属性正常工作。我使用这个列表来存储我的 JSON。一个字符串值,然后是列表中每个项目的整个对象。您会注意到,在 JSONToStringList 方法中,我清除了字符串列表(它被注释掉,因为如果没有注释掉,我的程序就会挂起)
2.) 在为所需的多个 JSON 集多次调用该方法后,我在列表中得到重复的值
TConnector = class(TComponent)
private
{ Private declarations }
FList: TStrings;
procedure SetList(const Value: TStrings);
protected
{ Protected declarations }
public
{ Public declarations }
Constructor Create( AOwner : TComponent ); override;
Destructor Destroy; Override;
Procedure GenerateJSON;
Procedure JSONToStringList(aJSonKey: String);
published
{ Published declarations }
property List: TStrings Read FList Write SetList;
end;
Constructor TConnector.Create(AOwner: TComponent);
begin
inherited;
FList:= TStringList.Create(True);
end;
destructor TConnector.Destroy;
begin
if FList <> nil then
FreeAndNil(FList);
inherited;
end;
Procedure TConnector.GenerateJSON;
begin
if ResponseStream<>nil then
Begin
FreeAndNil(ResponseJSON_V);
ResponseJSON_V := TJSONObject.ParseJSONValue(StreamToArray(ResponseStream),0) as TJSONValue;
End;
end;
procedure TConnector.JSONToStringList(aJSonKey: String);
Var
zLJsonValue : TJSONValue;
zLJSONArray: TJSONArray;
zLJsonObject : TJSONObject;
zI : Integer;
begin
if ResponseJSON_V is TJSONArray then
begin
zLJSONArray:= ResponseJSON_V as TJSONArray;
zLJsonObject := zLJSONArray.Get(0) as TJSONObject;
end
else
if ResponseJSON_V is TJSONObject then
begin
zLJSONArray:= nil;
zLJsonObject := ResponseJSON_V as TJSONObject;
end
else
Exit;
if zLJSONArray<>nil then
begin
***//FList.Clear;***
for zLJsonValue in zLJSONArray do
begin
zLJsonObject := zLJsonValue as TJSONObject;
for zI := 0 to zLJsonObject.Size-1 do
begin
if zLJsonObject.Get(zI).JsonString.Value = aJSonKey then
begin
FList.AddObject(zLJsonObject.Get(zI).JSONValue.Value, zLJsonObject);
end;
end;
end;
end
else
begin
FList.Clear;
for zI := 0 to zLJsonObject.Size-1 do
begin
if zLJsonObject.Get(zI).JsonString.Value = aJSonKey then
FList.AddObject(zLJsonObject.Get(zI).JSONValue.Value, TJSONPair(zLJsonObject.Get(zI)));
end;
end;
end;
我希望这一切都是可以理解的。如果您需要查看更多内容,请告诉我。请随时纠正您在我的代码中发现的任何其他问题。我一直在学习:) - 谢谢你的帮助
最佳答案
如果 FList.Clear 挂起,则很可能是内存损坏问题。我怀疑的第一件事是您没有调用构造函数或者该部分内存已被其他内容覆盖。
列表中的重复值是否是由于您注释掉了 FList.Clear 而导致的。无论如何,我建议使用调试器来查看列表中的内容或记录添加到列表中/从列表中删除的所有内容。这应该能让您了解列表中不需要的值来自何处。
作为一般建议,您无需在释放对象之前检查对象是否不为 nil。无论如何,检查都是在 Free 中(或在 FreeAndNil 的 Free 部分)中进行的。
关于使用 Delphi Xe5 将 JSON 转为 StringList,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19849428/
我使用 POI4XPages api 从 Word 文档创建了 PDF。这是代码: var template = poiBean.buildResourceTemplateSource(null,"p
我如何转换它: SELECT max(id), value FROM GROUP BY value; 能言善辩吗? 提前致谢!! 最佳答案 这应该可行,您可以在 https://laravel.co
我有Jquery点击事件,并且我想在执行我的函数UpdateItemStatus(this.id);之前防止多次点击,所以我已尝试使用开/关事件的以下代码, $('#tableItems').on('
有谁知道有什么软件包支持以下将base58转换为十六进制字符串或从十六进制字符串转换为base58编码的相反方式。下面是一个 python 实现的示例。 https://www.reddit.com/
我正在使用 Rob Monies 的“Jquery Week Calendar”来构建日历应用程序。 我有一个 MSSQL 数据库,其中包含名为“dates”的表和以下字段: ID开始结尾标题 我想用
我有一个以下形式的字典 >>> {'1' : [V3210 , 234567 ,1235675 , 23], '2' : [v3214 , 5678 ,65879 ,89} , ...} 如何将字典写
我有一堆 one 形式的变量, two , three , four_five我想把它们转到getOne , getTwo , getThree , getFourFive ... 我写了一个公式来实
这是我的第一个问题,我是初学者,代码是用 C (ANSI C) 编写的。 代码应该为递归函数中的每个数字返回数字 (n+1)。(123 -> 234; 801->912; 239->340) 问题是当
这可能是一个愚蠢的问题,但是我很难找到我需要的答案。我有一个计算中继器的测试。我想返回 count 变量,以便我可以将其传递给另一个测试以在 for 循环中使用。 我尝试过的: this.counts
我有这个字符串列表: private final List categoryList = Arrays.asList("27", "28, 96", "10", "15", "7", "98"); 从
我正在使用互操作将 excel 文件转换为 pdf。我有一个工作代码。 但在将其保存为 pdf 之前。它会提示一个对话框,要求用户“是否保存对文件的更改”我怎样才能避免这个提示? 保存完成后如何关闭e
我有一个 Canvas ,我想将其转换并显示在标签中。我知道我们可以使用 toDataURL() 和 toBlob() 将 Canvas 转换为图像,但这两种方法都给我 base64 数据,这不是图像
我有一个获取用户 profilePicture、lblUsername 和 lblEmail 的 Facebook 登录名。我知道 FBProfilePictureView 是一个包含 UIImage
我正在尝试使用 grunt-webfont 从 SVG 生成网络字体. 问题是我需要这个任务在 windows 和 linux 机器上有效。为了实现这一点,我需要使用 doesn’t work wit
我使用的是我在 GitHub 上发现的一个 JS 插件,它使视频标题出现视差,问题是当我运行它响应手机时视频变黑,我试图在响应模式下将视频更改为图像。 我尝试使用@mediatag 但无法正常工作。
我正在尝试学习 Go 并研究降雨强度工具。对于此工具,我必须进行如下计算: var intensity float32 intensity = 10^((value−109)÷32) 值是一个 uin
我有一个看起来像这样的字符串,例如 Lübeck Nürnberg Österreich 和“Umlaute”。 现在我想拆分它并在字符串上添加新的“单词”,如下所示Lübeck Nürnberg Ö
我的任务: 通过 ffmpeg 将 YUV Frame 数据转换为 jpeg 图像。 我有的: 每个平面的数据和每个平面的线尺寸; 我试图创建空的 AVFrame 并用这些信息填充它的数据和行大小,但
使用 Reflex-DOM,我想做一个 Event t ()当浏览器准备好绘制下一帧时触发,即 requestAnimationFrame火灾。我试过这样: {-# LANGUAGE Recursiv
我有一条路线 Route::post('/updateLogo', 'CaptivePortalController@updateLogo'); 然后我在这里发布 $http({ method
我是一名优秀的程序员,十分优秀!