我需要从移动应用程序解码以下 json
Array
(
[{"unm":"admin","pw”:”password”}] =>
)
我的PHP代码是
$obj1 = print_r($_REQUEST, true); //get $_request variable data(responce of login) data as it is
foreach($obj1 as $key => $value)
{
$obj2 = $key; //get first key
}
$obj3 = json_decode($obj2); //decode json data to obj3
$mob_user_name = $obj2['unm']; //getting json username field value
$mob_user_password = $obj2['pw']; //getting json password field value
希望这能解决您的问题,注意:内容只不过是您从iOS应用程序收到的内容
在内容 = 数组 ( [{"unm":"admin","pw":"password"}] => (
php
中解析它
$json = json_decode($content, true);
print json[0]['unm']; /* prints the username */
print json[0]['pw']; /* prints the password */
{"unm":"admin","pw”:”password”}
是一个对象,默认情况下,json_decode()
会这样构建它。
$obj = json_decode('{"unm":"admin","pw”:”password”}');
echo $obj->unm;
echo $obj->pw;
如果出于某种原因希望将其转换为关联数组,请将手册中指定的第二个参数 json_decode()
设置为 true
。
$arr = json_decode('{"unm":"admin","pw”:”password”}', true);
echo $arr['unm'];
echo $arr['pw'];