我必须生成没有任何数字序列的Json对象,我们将如何做?我必须将此Json信息插入表中,这将在此问题中使用please find here < / p>
我的json格式
{
"0": {
"0": "65",
"1": "PWD Road, B Narayanapura, Bengaluru, Karnataka, India",
"2": "JSS Layout, Mysore, Karnataka, India",
"3": "Bangalore",
"4": "ds",
"5": "you@gmail.com",
"6": "PWD Road, B Narayanapura, Bengaluru, Karnataka, India",
"7": "13-Feb-2015",
"8": "10:30 AM",
"9": "2",
"10": "1220000000",
"11": "Gajendra",
"cId": "65",
"address1": "PWD Road, B Narayanapura, Bengaluru, Karnataka, India",
"address2": "JSS Layout, Mysore, Karnataka, India",
"city": "Bangalore",
"comments": "ds",
"email": "you@gmail.com",
"landMark": "PWD Road, B Narayanapura, Bengaluru, Karnataka, India",
"scheduledDate": "13-Feb-2015",
"scheduledTime": "10:30 AM",
"services": "2",
"userContactNumber": "1220000000",
"userName": "Gajendra"
}
}
我已从上方删除数字序列并更改如下
{
"0": {
"cId": "65",
"address1": "PWD Road, B Narayanapura, Bengaluru, Karnataka, India",
"address2": "JSS Layout, Mysore, Karnataka, India",
"city": "Bangalore",
"comments": "ds",
"email": "you@gmail.com",
"landMark": "PWD Road, B Narayanapura, Bengaluru, Karnataka, India",
"scheduledDate": "13-Feb-2015",
"scheduledTime": "10:30 AM",
"services": "2",
"userContactNumber": "1220000000",
"userName": "Gajendra"
}
}
Myphp代码
<?php
header('Access-Control-Allow-Origin: *');//Should work in Cross Domaim ajax Calling request
mysql_connect("localhost","root","1212");
mysql_select_db("service");
$query="Select * from customer where services='2'";
$result=mysql_query($query);
if ( $result === false ) {
die("Can\'t do that: " . mysql_error());
}
$retVal = array();
//MYSQL_ASSOC remove key =field identifier
while( $row = mysql_fetch_array( $result, MYSQL_ASSOC ) ) {
$retVal[] = $row;
}
echo json_encode( $retVal );
答案 0 :(得分:3)
默认情况下mysql_fetch_array()返回一个包含所有字段两次的数组
a)key =字段标识符
b)key =字段位置
告诉myqsl_fetch_array将值只在其标识符名称下放入数组中:
while( $row = mysql_fetch_array( $result, MYSQL_ASSOC ) ) {