[英]Not able to access Json decoded array in php
I have Android application that sends a json string to PHP server and code is working fine on Android side but what i wants to do is to access JSon object php side and store it into database but i cant access it no matter what. 我有一个将json字符串发送到PHP服务器的Android应用程序,代码在Android端工作正常,但是我想做的就是访问JSon对象php端并将其存储到数据库中,但是无论如何我都无法访问它。 I returned what i was receiving at PHP end to android to see what i am getting.
我将我在PHP端收到的内容返回给android,以查看我得到了什么。
Thia is what application send to php servere Thia是什么应用程序发送到php服务器
[
{
"title ": "First entry ",
"address ": "Street 14, Lahore, Pakistan",
"longitude ": "74.322",
"latitude ": "31.5365"
},
{
"title ": "Second entry ",
"address ": "Street 14, Lahore, android ",
"longitude ": "74.322",
"latitude ": "31.5365"
},
{
"title ": "Third entry ",
"address ": "Street 14, Lahore, Lahore ",
"longitude ": "74.322",
"latitude ": "31.5365"
},
{
"title ": "Fgghh",
"address ": "Street 14, Lahore, Pakistan",
"longitude ": "74.3219",
"latitude ": "31.5364"
},
{
"title ": "Shsagcg. ",
"address ": "",
"longitude ": "74.2695",
"latitude ": "31.4626"
},
{
"title ": "Ggggfb",
"address ": "175 Block Q, Lahore, Pakistan",
"longitude ": "74.2693",
"latitude ": "31.4626"
},
{
"title ": "",
"address ": "Street 14, Lahore, Pakistan",
"longitude ": "74.322",
"latitude ": "31.5365"
}
]
Thia is what PHP server send back to application Thia是PHP服务器发回应用程序的内容
Array
(
[0] => Array
(
[title ] => First entry
[address ] => Street 14,
[longitude ] => 74.322
[latitude ] => 31.5365
)
[1] => Array
(
[title ] => Second entry
[address ] => Street 14, android
[longitude ] => 74.322
[latitude ] => 31.5365
)
[2] => Array
(
[title ] => Third entry
[address ] => Street 14,
[longitude ] => 74.322
[latitude ] => 31.5365
)
[3] => Array
(
[title ] => Fgghh
[address ] => Street 14,
[longitude ] => 74.3219
[latitude ] => 31.5364
)
[4] => Array
(
[title ] => Shsagcg.
[address ] =>
[longitude ] => 74.2695
[latitude ] => 31.4626
)
[5] => Array
(
[title ] => Ggggfb
[address ] => 175 Block Q,
[longitude ] => 74.2693
[latitude ] => 31.4626
)
[6] => Array
(
[title ] =>
[address ] => Street 14,
[longitude ] => 74.322
[latitude ] => 31.5365
)
)
This is what i receive and i tried to access single value with these commands + here is my php code. 这是我收到的,我尝试使用这些命令访问单个值,这是我的PHP代码。
<?php
$data = file_get_contents("php://input");
$arr = json_decode($data, true);
print_r($arr);// This commands return above string in same format.
?>
Commands i tried. 我尝试过的命令。
$title = $arr[0]['title'];// No success Eror = Undefined index
$title = $arr(0)// of course not success.
$title = $arr[0][1];
Is there any way to access this array. 有什么方法可以访问此数组。
您的阵列键似乎有一个尾随空格,因此请更改为:
$title = $arr[0]['title '];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.