suchen

自己写了个低版本实现JSON格式数据生成,但不知道对不对。2013-09-27修改上传
<?php <br /> /* <br>  * @ anthor:QD<br>  * @ time:  2013-09-27<br>  */<br> class json{<br> <br>     private $Arr = array();    //传入数组<br>     <br>     //构造器<br>     public function json($array)<br>     {<br>         if(!is_array($array)) return false;<br>         $this->Arr = $array;<br>     }<br>     //解析主函数<br>     public function MainArr()<br>     {<br>         $arr = $this->Arr;<br>         if($this->TypeArr($arr))<br>         {<br>             $json = $this->NumArr($arr);<br>         }<br>         else<br>         {<br>             $json = $this->IndexArr($arr);<br>         }<br>         return $json;<br>         <br>     }<br>     //解析索引数组<br>     public function IndexArr($arr)<br>     {<br>         $str ="";<br>         foreach($arr as $k=>$value)<br>         {<br>             if(is_array($value))<br>             {<br>                 if($this->TypeArr($value)) { $sun=$this->NumArr($value);}<br>                 else               {$sun=$this->IndexArr($value);}<br>                 if(strpos($sun,"}") || strpos($sun,"]"))<br>                 {<br>                     $str .= "\"".$k."\":".$sun.",";<br>                 }<br>                 else<br>                 {<br>                     $str .= "\"".$k."\":\"".$sun."\",";<br>                 }<br>             }<br>             else<br>             {<br>                  $str .= "\"".$k."\":\"".$value."\",";<br>             }<br>         }<br>         $str = "{".trim($str,",")."}";<br>         return $str;<br>     }<br>     //解析数字数组<br>     public function NumArr($arr) <br>     {<br>         $str = "";<br>         foreach($arr as $value)<br>         {<br>             if(is_array($value))<br>             {<br>                 if($this->TypeArr($value)) { $sun=$this->NumArr($value);}<br>                 else               {$sun=$this->IndexArr($value);}<br>                 if(strpos($sun,"}") || strpos($sun,"]"))<br>                 {<br>                     $str .= $sun.",";<br>                 }<br>                 else<br>                 {<br>                     $str .= "\"".$sun."\",";<br>                 }<br>             }<br>             else<br>             {<br>                 $str .= "\"".$value."\",";<br>             }<br>         }<br>         $str = "[".trim($str,",")."]";<br>         return $str;<br>     }<br>     //检验一个数组是不是严格数字索引   <br>     public function TypeArr($arr)<br>     {<br>         if(array_values($arr) === $arr) return true;<br>         return false;<br>     }<br>     <br> }<br> ?>

附件 json.zip ( 713 B 下载:31 次 )

AD:真正免费,域名+虚机+企业邮箱=0元

Stellungnahme
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn

Heiße KI -Werkzeuge

Undresser.AI Undress

Undresser.AI Undress

KI-gestützte App zum Erstellen realistischer Aktfotos

AI Clothes Remover

AI Clothes Remover

Online-KI-Tool zum Entfernen von Kleidung aus Fotos.

Undress AI Tool

Undress AI Tool

Ausziehbilder kostenlos

Clothoff.io

Clothoff.io

KI-Kleiderentferner

Video Face Swap

Video Face Swap

Tauschen Sie Gesichter in jedem Video mühelos mit unserem völlig kostenlosen KI-Gesichtstausch-Tool aus!

Heiße Werkzeuge

SublimeText3 chinesische Version

SublimeText3 chinesische Version

Chinesische Version, sehr einfach zu bedienen

VSCode Windows 64-Bit-Download

VSCode Windows 64-Bit-Download

Ein kostenloser und leistungsstarker IDE-Editor von Microsoft

Dreamweaver CS6

Dreamweaver CS6

Visuelle Webentwicklungstools

Dreamweaver Mac

Dreamweaver Mac

Visuelle Webentwicklungstools

SublimeText3 Linux neue Version

SublimeText3 Linux neue Version

SublimeText3 Linux neueste Version