繁体   English   中英

我需要在php上解析json url的帮助

[英]i need help on parsing json url on php

这是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
}

我正在寻找download_link的价值。 我怎样才能做到这一点?

这是我尝试的:

<?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;
 ?>

你需要:

- 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'];

您有一个包含另一个序列化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

暂无
暂无

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

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