简体   繁体   English

使用get或post方法将json从andriod发送到php并在php中提取json的值

[英]sending json from andriod to php using get or post method and exatract the values of json in php

I can send json from android to php but i'm unable to extract the data from json object in php.我可以将 json 从 android 发送到 php,但我无法从 php 中的 json 对象中提取数据。 Can anyone help me to that in php?任何人都可以在 php 中帮助我吗?

I tried json_decode($json) to decode the json data.我试过 json_decode($json) 来解码 json 数据。

What I was doing is I'm sending json object from android in get method and receiving the data in php side like this.. <?php $json=$_GET['data']; $d_json=json_decode($json) or json_decode($json,true); ?>我正在做的是我在 get 方法中从 android 发送 json 对象并在 php 端接收数据,就像这样.. <?php $json=$_GET['data']; $d_json=json_decode($json) or json_decode($json,true); ?> <?php $json=$_GET['data']; $d_json=json_decode($json) or json_decode($json,true); ?>

but when I was trying to access "$d_json['meal'][0]['name]" or "$d_json->meal[0]->name" it was showing illegal index.但是当我尝试访问“$d_json['meal'][0]['name]”或“$d_json->meal[0]->name”时,它显示了非法索引。

First I would try to print the $d_json to the screen - to see what is the value it holds.首先,我会尝试将 $d_json 打印到屏幕上- 看看它拥有什么价值。

If $d_json is not empty, but it is not an array (but a string) I would try a little bit of formatting:如果 $d_json 不为空,但它不是一个数组(而是一个字符串),我会尝试一些格式化:

$d_json = json_decode( stripslashes( $json ), true );

Then print_r (or var_dump, var_export) the result to see whether it returns an array.然后print_r(或var_dump、var_export)结果看是否返回数组。

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

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