The written JSON converts a class and method of an array, and in fact writes a method that converts most of the data structures that contain JSON strings to the array, on the code:
Copy Code code as follows:
Class Antitranjson
{
protected static function Jsontoarray ($json)
{
if (!is_string ($json) | | is_null (Json_decode ($json, True))
throw new Notjsonstringexception (' param ' not a JSON string ');
$deJson = Json_decode ($json, true);
Return Self::toarray ($deJson);
}
protected static function Stdclasstoarray ($STDS)
{
if (Is_object ($stds))
throw new Notobjectexception (' params not object ');
$params = Get_object_vars ($stds);
Return Self::toarray ($params);
}
protected static function Arrayrtoarray ($params)
{
$tmp = Array ();
if (!is_array ($params))
throw new Notarrayexception (' params not array ');
foreach ($params as $k => $v)
{
$tmp [$k] = Self::toarray ($v);
}
Var_dump ($TMP);
return $tmp;
}
Call this method, the data containing JSON can be converted
public static function ToArray ($params)
{
$tmp = Array ();
if (is_string ($params) &&!is_null (Json_decode ($params)))
$tmp = Self::jsontoarray ($params);
ElseIf (Is_array ($params))
$tmp = Self::arrayrtoarray ($params);
Notice here that if $params is an object, the conversion can only be achieved if the contained attributes are readable (public or temporary object attributes)
ElseIf (Is_object ($params))
$tmp = Self::stdclasstoarray ($params);
Else
$tmp = $params;
return $tmp;
}
The above is the relevant code, at least for the time being used still can be, if you have good suggestions, I hope you discuss the discussion, common progress, thank you