【问题标题】:How can I parse this JSON? [closed]如何解析这个 JSON? [关闭]
【发布时间】:2013-08-19 13:26:17
【问题描述】:

我无法使用 PHP 从 JSON 中获取“img_url”(第三行)值。这是 JSON 字符串:

编辑(这是 JSON,我很抱歉发布 var_dump):

{"status_code":200,"status_txt":"OK",
"data":{"img_name":"KdxIC.png","img_url":"http:\/\/s0.uploads.im\/KdxIC.png",
"img_view":"http:\/\/uploads.im\/KdxIC.png","img_width":"504","img_height":"504",
"img_attr":"width=\"504\" height=\"504\"","img_size":"15.1 KB","img_bytes":15494,
"thumb_url":"http:\/\/s0.uploads.im\/t\/KdxIC.png","thumb_width":360,"thumb_height":360,
"source":"http:\/\/site.com\/uploads\/icon1@2x.png","resized":"0","delete_key":"6e814d3c5201feee"}}

接受的答案有效。谢谢

【问题讨论】:

  • 您尝试的解决方案在哪里?
  • 我从未见过像这样的 JSON...返回此数据的原因是什么?
  • 这不是 JSON(它可能是 PHP 中 json_parsing 一些 JSON 的结果转储)。
  • 我试过 $json = json_decode($response, true);回声 $json["data"]["img_url"];等等,但我总是一无所获
  • 这是uploads.im的回应

标签: php html json parsing url


【解决方案1】:

该代码不是 json,它是一个数组的 php 转储。

如果您想访问图片网址,请执行以下操作:
我正在使用example url。

$imgdata = json_decode($response, true);
echo $imgdata["data"]["img_url"];

输出:

http://s0.uploads.im/go0WK.png


编辑:
不要使用json_decode 中的第二个参数,即将对象转换为数组。

【讨论】:

  • 您是如何得到回复的?我正在使用 file_get_contents() 但没有运气。
  • 我试过这个: $img = json_decode(file_get_contents('uploads.im/api?upload=http://www.google.com/images/srpr/…));回声$img->数据->img_url;而且效果很好!
  • 谢谢!终于可以一路运行了。
猜你喜欢
  • 1970-01-01
  • 2012-05-01
  • 2021-06-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-06-09
  • 2013-06-07
相关资源
最近更新 更多