PHP 与 js json的通信实例

作者:简简单单 2010-11-17

选简介一下json吧,json(网页特效 object notation) 是一种轻量级的数据交换格式。易于人阅读和编写。同时也易于机器解析和生成。它基于javascript programming language, standard ecma-262 3rd edition - december 1999的一个子集。 json采用完全独立于语言的文本格式,但是也使用了类似于c语言家族的习惯(包括c, c++, c#, java, javascript, perl, python等)。这些特性使json成为理想的数据交换语言。

json建构于两种结构:


“名称/值”对的集合(a collection of name/value pairs)。不同的语言中,它被理解为对象(object),纪录(record),结构(struct),字典(dictionary),哈希表(hash table),有键列表(keyed list),或者关联数组 (associative array)。
值的有序列表(an ordered list of values)。在大部分语言中,它被理解为数组(array)。


php文件代码

$res['id'] = $_post['id'];
$res['name'] = "elar";
$res['age'] = "21";
$response = "hello this is response".$_post['id'];
echo json_encode($res);
?>

js代码

 





相关文章

精彩推荐