This paper mainly introduces the method of transforming Index association data into JSON object in PHP, and analyzes the conversion technique of PHP array and JSON format data based on YII framework. We hope to help you.
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;}
Related recommendations:
PHP solve JSON Chinese display problem
A sample usage of PHP JSON-related functions
PHP JSON vs. XML serialization/deserialization