Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/363.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何从字符串数组中获取值_Javascript_Jquery_Html_Arrays_String - Fatal编程技术网

Javascript 如何从字符串数组中获取值

Javascript 如何从字符串数组中获取值,javascript,jquery,html,arrays,string,Javascript,Jquery,Html,Arrays,String,下面是一个字符串数组。我的目标是从这个长字符串中检索链接“” config={ "canvas": { "backgroundColor": "transparent", "backgroundGradient": "none" }, "showErrors": false, "key": "#$c7ea0997604dc901178", "contextMenu": [ "Google" ],

下面是一个字符串数组。我的目标是从这个长字符串中检索链接“”

config={
    "canvas": {
        "backgroundColor": "transparent",
        "backgroundGradient": "none"
    },
    "showErrors": false,
    "key": "#$c7ea0997604dc901178",
    "contextMenu": [
        "Google"
    ],
    "playlist": [
        {
            "url": "http://www.google.com",
            "autoPlay": false,
            "scaling": "scale",
            "provider": "lighttpd"
        }
    ],
    "logo": {
        "opacity": 1,
        "right": 20,
        "url": "http://www.image.com",
        "fullscreenOnly": true,
        "top": 20
    },
    "screen": {
        "top": 0,
        "height": "100pct"
    },
    "plugins": {
        "controls": {
            "timeColor": "#ffffff",
            "borderRadius": 4,
            "bufferGradient": "none",
            "backgroundColor": "transparent",
            "volumeSliderGradient": "none",
            "timeBorderRadius": 0,
            "progressGradient": "none",
            "time": true,
            "height": 33,
            "volumeColor": "rgba(0, 145, 255, 1)",
            "tooltips": {
                "marginBottom": 5,
                "buttons": true
            },
            "opacity": 1,
            "volumeSliderColor": "rgba(66, 66, 77, 1)",
            "bufferColor": "#26ACFF",
            "border": "0px",
            "buttonColor": "rgba(0, 145, 255, 1)",
            "mute": false,
            "autoHide": {
                "enabled": true,
                "hideDelay": 3000,
                "mouseOutDelay": 3000,
                "hideStyle": "fade",
                "hideDuration": 3000,
                "fullscreenOnly": false
            },
            "backgroundGradient": [
                0.5,
                0.2,
                0
            ],
            "width": "99pct",
            "display": "block",
            "buttonOverColor": "rgba(0, 225, 255, 1)",
            "url": "http://www.video.com",
            "fullscreen": true,
            "timeBgColor": "rgba(0, 0, 0, 0)",
            "borderWidth": 0,
            "scrubberBarHeightRatio": 1,
            "bottom": "5pct",
            "buttonOffColor": "rgba(90,90,90,1)",
            "sliderColor": "rgba(0, 0, 0, 1)",
            "borderColor": "rgba(0, 0, 0, 0)",
            "zIndex": 1,
            "scrubberHeightRatio": 0.5,
            "tooltipTextColor": "rgba(33, 96, 255, 1)",
            "spacing": {
                "all": 0
            },
            "sliderGradient": "none",
            "timeBgHeightRatio": 0.7,
            "volumeSliderHeightRatio": 0.4,
            "name": "controls",
            "volumeBarHeightRatio": 0.6,
            "left": "50pct",
            "tooltipColor": "#C9C9C9",
            "durationColor": "rgba(0, 145, 255, 1)",
            "progressColor": "#0099FF",
            "timeBorder": "1px solid rgba(0, 0, 0, 0.3)",
            "volumeBorderRadius": 0,
            "scrubberBorderRadius": 0,
            "volume": true,
            "builtIn": false,
            "margins": [
                0,
                0,
                0,
                0
            ]
        },
        "lighttpd": {
            "url": "http://www.title.com"
        },
        "liverail": {
            "url": "http://www.title.com"
        }
    }
}
}}

这不是一个数组,而是一个javascript对象

查看javascript对象的任何简单方法都是将其放入。验证器说对象实际上是无效的;它有两个额外的闭合支架


如果它是有效的,您可以使用
config.playlist.url
获取所需的链接。

由于它是一个JSON对象,您需要通过调用属性来获取url,因此它看起来像这样:

var url = config.playlist[0].url

感谢@Igor指出playlist是一个数组

这是一个json对象,而不是stringconfig.playlist[0]。url?