How to decode JSON string in PHP pass from android?

别来无恙 提交于 2021-02-08 09:24:27

问题


I want to decode json string in Php that is pass from android.

Suppose i have follwing json that comes from android
{"name":"ajay"} and in php i do

<?php
$result=json_decode('$_POST',true);
$name=$result['name'];
$response=array();
$response["message"]=$name successfully parse in php;
echo json_encode($response);
?>

This gives html tag in response.Is there is any way to solve this?


回答1:


Follow this link. Maybe this will be helpful:

http://www.php.net/manual/en/function.json-decode.php




回答2:


This seems working fine for me

<?php
  $result=json_decode('{"name":"ajay"} ',true);
  $name=$result['name'];
  $response=array();
  $response["message"]="$name successfully parse in php";
  echo json_encode($response);
?>

Check php manual for json_decode for more



来源:https://stackoverflow.com/questions/23907165/how-to-decode-json-string-in-php-pass-from-android

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!