1

这是json内容:

{
   "success":true,
    "data":"{\"campaign_name\":\"helloworld\",\"download_link\":\"https:\\\/\\\/google.com\\\/accesskey\\\/getfile\\\/m-spqn-e61-2aef2575a0b5250354f2b0fda033e703?token=HUSYjdC5jyJskXUHiKn13l1A1BaAjH2R&dcma=5ecceb0522bcd0db\",\"link\":\"http:\\\/\\\/www.lol.com\\\/remove\\\/remove.php\"}",
    "message":null
}

我正在寻找下载链接的价值。我怎样才能做到这一点?

这是我尝试过的:

<?php
$jsndata = {"success":true,"data":"{\"campaign_name\":\"helloworld\",\"download_link\":\"https:\\\/\\\/google.com\\\/accesskey\\\/getfile\\\/m-spqn-e61-2aef2575a0b5250354f2b0fda033e703?token=HUSYjdC5jyJskXUHiKn13l1A1BaAjH2R&dcma=5ecceb0522bcd0db\",\"link\":\"http:\\\/\\\/www.lol.com\\\/remove\\\/remove.php\"}","message":null};
$jsn = json_decode($jsndata,true);

$temperatureMin = $jsn['data'][6]['download_link'];
echo $temperatureMin;
 ?>
4

2 回答 2

0

您有一个包含另一个序列化 json 对象的 json 对象。

解码第一个对象,获取第二个序列化对象并解码:

$jsndata = '{
    "success":true,
    "data":"{\"campaign_name\":\"helloworld\",\"download_link\":\"https:\\\/\\\/google.com\\\/accesskey\\\/getfile\\\/m-spqn-e61-2aef2575a0b5250354f2b0fda033e703?token=HUSYjdC5jyJskXUHiKn13l1A1BaAjH2R&dcma=5ecceb0522bcd0db\",\"link\":\"http:\\\/\\\/www.lol.com\\\/remove\\\/remove.php\"}",
    "message":null
}';

// Decode the main json object
$jsn = json_decode($jsndata,true);

// Since 'data' is another serialized object, you need to decode that as well:
$data = json_decode($jsn['data'], true);

// Now you can access the contents of 'data'
echo $data['download_link'];

演示:https ://3v4l.org/1PcQp

于 2018-06-06T14:08:44.403 回答
0

你需要:

- quotes around your JSON
- to remove the quotes around the inner object

$jsndata = '{"success":true,"data":{\"campaign_name\":\"helloworld\",\"download_link\":\"https:\\\/\\\/google.com\\\/accesskey\\\/getfile\\\/m-spqn-e61-2aef2575a0b5250354f2b0fda033e703?token=HUSYjdC5jyJskXUHiKn13l1A1BaAjH2R&dcma=5ecceb0522bcd0db\",\"link\":\"http:\\\/\\\/www.lol.com\\\/remove\\\/remove.php\"},"message":null}' ;

你需要[6]从你的数组访问中删除:

$temperatureMin = $jsn['data']['download_link'];
于 2018-06-06T14:03:13.347 回答