Home > Backend Development > PHP Tutorial > json_encode之后,json数据变成[{"a""1"}],如何改成{"a""1"}

json_encode之后,json数据变成[{"a""1"}],如何改成{"a""1"}

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-13 12:14:57
Original
1098 people have browsed it

json_encode之后,json数据变成[{"a","1"}],怎么改成{"a","1"}

<br />function get_js_array($sql){<br />	$result = mysql_query($sql);<br />	$arr = array();<br />	while($row = mysql_fetch_array($result, MYSQL_ASSOC)){<br />		$arr[] = $row;  <br />	}<br />	$js = json_encode($arr);<br />	mysql_free_result($result);<br />	mysql_close($conn);<br />	return $js;<br />}<br />
Copy after login


求根据这个改写一下。。 谢谢
------解决思路----------------------
$js = json_encode(array_pop($arr));
------解决思路----------------------
$js = trim(json_encode($arr), '[]');

你这个需求很奇怪,本来是数组,却不用数组表示

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template