PHP implements the method of converting indexed associative data in arrays into JSON objects, data conversion JSON
In this paper, we describe the method of transforming indexed associative data into JSON objects in a PHP implementation array. Share to everyone for your reference. The implementation method is as follows:
public static function encode (& $var) {return ' {'. Implode (', ', Self::encodeexcute ($var)). '} '; private static function Encodeexcute (& $var) {$json = array (); Switch (GetType ($var)) {case ' array ': foreach ($var as $key = $value) { if (Is_array ($value)) { $json [] = ' "'. $key. '": {'. Implode (', ', Self::encodeexcute ($value)). '} '; $json [$key] = Self::encode ($value); } ElseIf (Is_object ($value)) { $json [] = "\ \" {$key}\\ ":". Json_encode ($value->attributes); } else { echo ' ERROR unknown type, not yet resolved '; Yii::app ()->end (); } } break; Case ' object ': Break ;} return $json;}
I hope this article is helpful to everyone's PHP programming.
http://www.bkjia.com/PHPjc/1028965.html www.bkjia.com true http://www.bkjia.com/PHPjc/1028965.html techarticle PHP implements the method of transforming indexed associative data into JSON objects in an array, and the data conversion JSON example describes how to convert indexed associative data in a PHP implementation array into a JSON object. Share to the big ...