-2

PHP を使用して JSON から "img_url" (3 行目) の値を取得できません。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"}}

受け入れられた答えは機能します。ありがとう

4

1 に答える 1

2

そのコードはjsonではなく、配列のphpダンプです。

画像の URL にアクセスしたい場合は、次のようにします:
I'm using this example url .

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

出力:

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


編集:オブジェクトを配列に変換する
の 2 番目のパラメーターを使用しないでください。json_decode

于 2013-08-19T13:38:16.613 に答える