简体   繁体   English

如何从Android解码PHP传递中的JSON字符串?

[英]How to decode JSON string in PHP pass from android?

I want to decode json string in Php that is pass from android. 我想在Php中解码android传递的json字符串。

Suppose i have follwing json that comes from android 假设我有以下来自Android的json
{"name":"ajay"} and in php i do {“ name”:“ ajay”},在php中

<?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? 这会给html标签一个响应。有什么办法可以解决这个问题?

Follow this link. 点击此链接。 Maybe this will be helpful: 也许这会有所帮助:

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

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 检查php手册中的json_decode以获得更多信息

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM