本文目录一览:
- 1、php 循环判断,判断json里面的数据,大神们帮帮忙啊
- 2、客户端如何写一个ajax请求,来读取php传递出的json数据(为浮点型)?然后可以与文本框输入的数据比较?
- 3、php json输出的结果格式,PHP是怎么写的?谢谢
php 循环判断,判断json里面的数据,大神们帮帮忙啊
$str = '{"queryString":"select id , name from user LIMIT 0, 30 ","data":[{"0":"1","id":"1","1":"aa","name":"aa"},{"0":"2","id":"2","1":"\u5c0f\u4f19\u4f34","name":"\u5c0f\u4f19\u4f34"},{"0":"3","id":"3","1":"\u5c0f\u4f19\u4f34","name":"\u5c0f\u4f19\u4f34"},{"0":"4","id":"4","1":"44","name":"44"},{"0":"5","id":"5","1":"","name":""},{"0":"6","id":"6","1":"","name":""},{"0":"7","id":"7","1":"","name":""},{"0":"8","id":"8","1":"","name":""},{"0":"9","id":"9","1":"","name":""},{"0":"10","id":"10","1":"jiejie","name":"jiejie"},{"0":"11","id":"11","1":"jiejie","name":"jiejie"}]}';
foreach (json_decode($str) as $v)
{
if(is_array($v))
{
foreach($v as $value)
{
echo "当前的name 为: {$value-name} id : {$value-id}";
}
}
}
中文不管 你取得是对应的name值
客户端如何写一个ajax请求,来读取php传递出的json数据(为浮点型)?然后可以与文本框输入的数据比较?
在服务器将数据转换为JOSN格式
由于数据库储存的数据(一般情况下)是不变的,将返回的结果储存到数组中(用定时器太烧性能)
server.php服务端:
//将数据库获取的数据转换为Json格式并返回前端
$json = array(); //先定义一个空数组来存储。
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
array_push($json, array("id" = $row['id'], "name" = $row['name'])); //其他数据自己补充
}
echo json_encode(array("json" = $json));
前端:
$(document).ready(function(){
$.getJSON("", function(data){
var array = data.json.slice(); //数据克隆
});
});
比较输入大小,用循环跟数组比较。
全栈之路不好走
php json输出的结果格式,PHP是怎么写的?谢谢
php里面直接用数组表示,你的这个数组就像下面: $a = array('allcount'=107,'listurl'='house','project'=array('projcode'=3410877100,projname='rrr','housecount'=5981));
然后直接转换成json代码就可以了: echo json_encode($a);