这是一个关于使用Json数据的一个例子,本例子为了方便演示“鬼”的存在,作了精简,希望大虾能够把鬼捉出来

解决方案 »

  1.   

    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls,UJsonD6;type
      TForm1 = class(TForm)
        Button1: TButton;
        procedure Button1Click(Sender: TObject);
      private
        { Private declarations }
        JsonPara:TJsonObject;
        procedure Test(str:string);
      public
        { Public declarations }
      end;var
      Form1: TForm1;implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
    var
      SubJson,Json:TJsonObject;
    begin
      json:=TJsonObject.create;
      json.put('FuncName','Open');
      json.put('FilePath','');  SubJson:=TJsonObject.create;
      SubJson.put('FileUID','aaa-bb-ccc-ddd');
      SubJson.put('SFileName','ttttttttt.dot');
      json.put('FileDataInfo',SubJson);  Test(Json.AsJson);
      json.Free;
    end;procedure TForm1.Test(str:string);
    var
      subJson:TJsonObject;
    begin
      ShowMessage(subJson.getString('FileUID'));
      exit;
      JsonPara.AsJson:=str;
    end;end.
      

  2.   

    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls,UJsonD6;type
      TForm1 = class(TForm)
        Button1: TButton;
        procedure Button1Click(Sender: TObject);
      private
        { Private declarations }
        JsonPara:TJsonObject;
        procedure Test(str:string);
      public
        { Public declarations }
      end;var
      Form1: TForm1;implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
    var
      SubJson,Json:TJsonObject;
    begin
      json:=TJsonObject.create;
      json.put('FuncName','Open');
      json.put('FilePath','');  SubJson:=TJsonObject.create;
      SubJson.put('FileUID','aaa-bb-ccc-ddd');
      SubJson.put('SFileName','ttttttttt.dot');
      json.put('FileDataInfo',SubJson);  Test(Json.AsJson);
      json.Free;
    end;procedure TForm1.Test(str:string);
    var
      subJson:TJsonObject;
    begin
      ShowMessage(subJson.getString('FileUID'));
      exit;
      JsonPara.AsJson:=str;
    end;end.
      

  3.   

    一不小心,重发了代码
    各位请注意
    procedure TForm1.Test(str:string);
    var
      subJson:TJsonObject;
    begin
      ShowMessage(subJson.getString('FileUID'));
      exit;
      JsonPara.AsJson:=str;
    end; 这段代码,Test在函数Button1Click中被调用,subJson没有作任何初始化,甚至没有创建,居然可以正确读取FileUID的信息,
    另外
    exit;
    JsonPara.AsJson:=str;
    可以说是两句废话,但是,删除JsonPara.AsJson:=str;,subJson就无法读取FileUID的信息,
    这到底是为什么???????
      

  4.   

    不会是因为有了
    JsonPara.AsJson:=str; 
    才能自动初始化的吧虽然在执行的时候没作用
      

  5.   

    有愿意捉鬼的请留下Email,我把源代码发过去
      

  6.   

    不会是因为有了
    JsonPara.AsJson:=str;
    才能自动初始化的吧虽然在执行的时候没作用
    ------------------------
    想不通啊,根本就没有执行这句话,我测试的时候把代码优化功能关闭,也是如此,一句根本就不执行的语句如何影响另外一个对象?
      

  7.   

    而且,JsonPara 也没有实例化,就算编译器自作主张先执行
    JsonPara.AsJson:=str; 
    理论上,这一样会崩溃
    有需要源代码的,请留下Email,我把代码发过去
      

  8.   

    你把代码传到资源里去,大家一起来“捉”http://d.download.csdn.net/down/1283448/ylm163net
    下不了
      

  9.   

    UJsonD6
    ????????????
      

  10.   

    就是Ujson.pas,网上可以搜索到,这个单元主要是做了一个类TJsonObject用于解析Json
    为了方便使用,我自己增加了一个属性AsJson,就把单元名称改了,以区别原先的文件
      

  11.   

    我已经上传了整套代码,但是我看不到我的资源,我晚上在想办法发布UjsonD6这个文件
      

  12.   

    这是源代码
    http://www.jsyisu.com/JsonError.rar