php对json的操作

<?php

header('Content-type:text/html; charset=UTF-8');
$isArray = true;
$jsonData ='[{"Name":"小明","Age":20},{"Name":"小明","Age":20}]';
$jsonArray = json_decode($jsonData,$isArray);
foreach ($jsonArray as $item){
	echo $item['Name'];
}
echo '<br>'.preg_replace("#\\\u([0-9a-f]+)#ie", "iconv('UCS-2', 'UTF-8', pack('H4', '\\1'))", json_encode($jsonArray));
?>

 

输出为

小明小明
[{"Name":"小明","Age":20},{"Name":"小明","Age":20}]




session_start();
include_once( 'config.php' );
include_once( 'saetv2.ex.class.php' );

function get_response_as_string($url)
{
	$html = file_get_contents($url);
	return $html;
}

$c = new SaeTClientV2( WB_AKEY , WB_SKEY , $_SESSION['token']['access_token'] );


$username = $_REQUEST["username"];
$password = $_REQUEST["password"];

$mysql  = new SaeMysql();

$sqlText = "INSERT INTO `app_aidaren`.`user` (`username`, `password`, `name`) VALUES ('.$username.', '.$password.', '.$username.')";

if(isset($username)){
	$mysql->runSql( $sqlText );
}

$sqlText = "select * from user";
	$data = $mysql->getData( $sqlText );
	$line = count($data);
	for($i=0;$i<$line;$i++)
	{
		echo "username:".$data[$i]['username']."    "."password:".$data[$i]['password']."<br>";
	}
	$mysql->closeDb();
?> 

你可能感兴趣的:(json)