从< script>解析json数据使用simple_html_dom库标记 [英] Parse json data from <script> tag using simple_html_dom library

查看:88
本文介绍了从< script>解析json数据使用simple_html_dom库标记的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在html源代码中有此数据.

I have this data in the html source.

    <script type="application/ld+json">
    [{"@context:":"http:\/\/schema.org","@type":"Movie","name":"My First Movie"}]
    </script>

现在,我想使用simple_html_dom php库从此json数据(如类型,电影)中进行解析.我已经到了

Now i want to parse from this json data like type, movie using simple_html_dom php library. I have gone upto

    $des = $html->find('script', 1)->innertext;
    $desDecode = json_decode($des);

使用此代码,我得到了 [{"@ context:":"http:\/\/schema.org","@ type":电影",名称":我的第一部电影"}]但是在此之后,我很困惑如何获取电影或名称之类的价值.我无法从这里开始找到json对象的名称.请对此提供一些提示.

Using this I got [{"@context:":"http:\/\/schema.org","@type":"Movie","name":"My First Movie"}]But after this I am confused how to get value like Movie or name. I cant find the json object name here from where I can start. Please give some light on this.

推荐答案

检查此代码,我认为您得到了这样的json响应.

Check this code i think you got json response like this.

$html = '<script type="application/ld+json">
[{"@context:":"http:\/\/schema.org","@type":"Movie","name":"My First Movie"}]
</script>';

 $des = strip_tags($html);
$desDecode = json_decode($des);

print_r($desDecode);

这篇关于从&lt; script&gt;解析json数据使用simple_html_dom库标记的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆