php中构造json数组,php – 在循环中构造json数组

这是我构建动态json的Query

$Query = "SELECT url as src, notes as text, `x-axis` as x, `y-axis` as y, width as width, height as height FROM annotate where `url` ='".$url."' limit 0,10 ";

$Result = $Connection->query($Query);

$Data = $Result->fetch_assoc();

$result=array();

$i=0;

while($row = $Result->fetch_assoc()){

$result[$i]['src']=$row['src'];

$result[$i]['text']=$row['text'];

$result[$i]['shapes']['type']= 'rect';

$result[$i]['shapes']['geometry'] =array('x' => $row['x'], 'y'=> $row['y'], 'width' => $row['width'], 'height'=>$row['height'] );

$i++;

}

echo json_encode($result);

这是预期的输出和实际输出….

第一个是预期的数据控制台(我将控制台设置为静态)实际输出是第二个.

这是用于控制静态输出的变量.

var my = {

src : 'http://192.168.1.58/annotate/drive/image/<?php echo $_GET['file']?>',

text : 'Suresh and Gopinath....',

shapes : [{

type : 'rect',

geometry : { x : 0.1825726141078838, y: 0.23756906077348067, width : 0.11602209944751381, height: 0.11618257261410789 }

}]

}

我怎样才能像第一个那样将形状作为数组?

76oeV.png

注意 :

这个问题是this one的延续

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值