PHP数组到JSON字符串
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了PHP数组到JSON字符串相关的知识,希望对你有一定的参考价值。
SEE http://json.org/ for php JSON Libraries.grunt knuckle drag brute force ugly escapes for quotes make a php array a json string
Produces trailing commas which some javascript Librarys can't deal with.*
_*NOOB NOTE [a comma is added at the end of each array key/value set]_
function array_to_json_string($arraydata) { $output = ""; $output .= "{"; foreach($arraydata as $key=>$val){ if (is_array($val)) { $output .= """.$key."" : [{"; foreach($val as $subkey=>$subval){ $output .= """.$subkey."" : "".$subval."","; } $output .= "}],"; } else { $output .= """.$key."" : "".$val."","; } } $output .= "}"; return $output; }
以上是关于PHP数组到JSON字符串的主要内容,如果未能解决你的问题,请参考以下文章