Monday, 26 August 2013

Deserialize a class within a class from a JSON query in PHP

Deserialize a class within a class from a JSON query in PHP

I have two classes like this (as it is in C#)
public class inside
{
public string name {get;set;}
public int id {get;set;}
public string value {get;set;}
}
public class outside
{
public inside[] items {get;set;}
}
I then do a query to the server and deserialize the JSON values that come
back into the outside class.
I've been asked if I can port this over to PHP and I've come up with
class inside
{
public $name;
public $id;
public $value;
}
class outside
{
public array $item -> inside;
with pretty much everything else coming from Deserializing from JSON into
PHP, with casting?
for the outside class deserialization.
No real surprise in that it doesn't actually work for me (I stopped doing
PHP years ago as it annoyed the hell out of me that PHP was an all or
nothing language - if you don't see something, something is wrong)
The stumbler I think is how to I link the inside class to the outside
class in the same way as I would in C#?

No comments:

Post a Comment