2011-07-29 119 views
1

我有以下結構,並且您可以看到json中沒有返回「methods」數據。爲什麼? 這是一個UML建模程序。Json_encode缺失數據

object(UClass)[1] 
    public 'classname' => string 'Class_Temp_1311967657' (length=21) 
    public 'classtype' => string 'public' (length=6) 
    public 'methods' => 
    array 
     0 => 
     object(UFunction)[2] 
      private 'name' => string 'Bill' (length=4) 
      private 'type' => null 
      private 'attributes' => null 
      private 'returntype' => null 
     1 => 
     object(UFunction)[3] 
      private 'name' => string 'Function_Temp_1311967657' (length=24) 
      private 'type' => null 
      private 'attributes' => null 
      private 'returntype' => null 
    public 'attributes' => 
    array 
     'person' => 
     array 
      'type' => string 'string' (length=6) 
      'visability' => string 'public' (length=6) 
     'id' => 
     array 
      'type' => string 'int' (length=3) 
      'visability' => string 'public' (length=6) 
    private 'interfacesUsed' => 
    array 
     empty 

並且json看起來像這樣

{"classname":"Class_Temp_1311967657","classtype":"public","methods":[{},{}],"attributes":{"person":{"type":"string","visability":"public"},"id":{"type":"int","visability":"public"}}} 

回答

4

因爲私有成員不被json_encode序列化。

+1

也許你可以創建一個公共方法「toJson()」,也可以序列化私有成員? –

+0

啊。謝謝你錯過了。 – mike628