2

I have the following structure, and as you can see the "methods" data is not returned in the json.Why? This is a UML modeling program.

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

And the json looks like this

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

1 Answer 1

6

Because private members aren't serialized by json_encode.

Sign up to request clarification or add additional context in comments.

1 Comment

Perhaps you could create a public method "toJson()" that also serializes the private members?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.