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

How to get the the value from string array

本文关键字:获取 数组 字符串      更新时间:2023-09-26

下面是一个字符串数组。我的目标是从这个长字符串中检索链接"http://www.google.com"。

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"
        }
    }
}
}}

因为它是一个JSON对象,你需要通过调用属性来获取url,所以它看起来像这样:

var url = config.playlist[0].url

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

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

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

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