0

如何在 php 中回显 json?服务器向我发送 json。

$i=$_POST["id"];
if($i==1){

// here i must echo this

{

"item": 

{
        "html": 
[{

"description": "some text",
            "n": "1"
        }],
        "table": {

            "1": {

                "line": [{

                    "number": "",

                    "value": ""

                }

                ]
            }

        },
        "videos": [],

        "urlext": [],

        "imgs": [ {

            "size": {

                "root": "xxx xxx"

            }

        }]

    }

}


}
else {

// here i must echo another one

{

"item": 

{
        "html": 
[{

"description": "some text",
            "n": "1"
        }],
        "table": {

            "1": {

                "line": [{

                    "number": "",

                    "value": ""

                }

                ]
            }

        },
        "videos": [],

        "urlext": [],

        "imgs": [ {

            "size": {

                "root": "xxx xxx"

            }

        }]

    }

}


}


} 
4

1 回答 1

1

只需构建您需要作为 json 发送并用于json_encode()呈现 json的数据的关联数组

$data = array( 'name' => 'foo',
               'some' => 'thing' 
);

echo json_encode($data);
于 2013-02-25T14:21:36.980 回答