0
JSON对象我不得不发送JSON在以下格式:编码数据转换成在PHP
{
"suomottoRegVO" : {
"rgdtls" : {
"aplty" : APLSM
},
"docls" : [
{
"id" : 123,
"ty" : 101,
},
{
"id" : 123,
"ty" : 101,
}
],
"todtls":{
"tonm":"Gaurav Kumar",
"todg":"Tax Official",
"pl":"Bangalore",
"dt":" 12-04-2015 23:05:23"
}
}
}
我使用以下代码以它编码成JSON和自docls是数组,我使用的是循环将两个值放入其中。
$json_string = array(
'suomottoRegVO' => array (
'rgdtls'=> array(
'aplty'=>'APLSM',
),
'todtls' => array(
'tonm' => 'Gaurav Kumar',
'todg' => 'Tax Official',
'pl' => 'Bangalore',
'dt' => ' 12-04-2015 23:05:23',
)
)
);
for ($i=0; $i<2; $i++) {
$docls[] = array (
'id' => '123',
'ty' => '101'
);
}
$json_string['docls']=$docls;
json_encode($json_string);
当我打印JSON,就变成:
{
"suomottoRegVO" : {
"rgdtls" : {
"aplty" : APLSM
},
"todtls":{
"tonm":"Gaurav Kumar",
"todg":"Tax Official",
"pl":"Bangalore",
"dt":" 12-04-2015 23:05:23"
}
}
"docls" : [
{
"id" : 123,
"ty" : 101,
},
{
"id" : 123,
"ty" : 101,
}
],
}
的 “docls” 应该是里面的 “suomottoRegVO”,但并非如此。请任何人指导我解决这个问题。
为什么两次? '$ I <2'? – devpro
用户可以上传'n'个文档。我只显示了2. –