dongshi2836 2014-05-15 06:47
浏览 40

无法访问php中的Json解码数组

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. I returned what i was receiving at PHP end to android to see what i am getting.

Thia is what application send to php servere

[
    {
        "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

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


$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.

  • 写回答

1条回答 默认 最新

  • dongzhiqi0332 2014-05-15 06:50
    关注

    Your array keys appear to have a trailing space, so change to:

    $title = $arr[0]['title '];
    
    评论

报告相同问题?

悬赏问题

  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 软件测试决策法疑问求解答
  • ¥15 win11 23H2删除推荐的项目,支持注册表等
  • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
  • ¥15 qt6.6.3 基于百度云的语音识别 不会改
  • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
  • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
  • ¥20 测距传感器数据手册i2c