如何从字符串数组中获取值
How to get the the value from string array
下面是一个字符串数组。我的目标是从这个长字符串中检索链接"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
获取您想要的链接。
相关文章:
- 获取数组的总值
- 按最大值获取数组索引
- React.js如何从js文件中获取数组
- TinyMCE获取数组数据
- 如何获取数组详细信息另一页
- 使用javascript从节点属性获取数组值
- 使用JavaScript获取数组中表单的所有控件
- 获取数组的长度-打印不正确的值
- 正在从JSON对象获取数组
- 什么'获取数组的已定义部分的最快方法是什么?JS
- 如何使用angular指令从html中获取数组
- 如何获取数组中数字的最大出现次数
- 根据优先级获取数组的值
- JAVASCRIPT:获取数组中的值
- 获取数组的元素,无论索引的大小如何
- JavaScript:在XML中搜索节点并从该节点获取数组
- 无法获取数组的长度
- 在数字索引循环中获取数组项的键
- 如何使用JavaScript或jQuery获取数组中选定的optgroup和选项
- Javascript-函数获取数组元素参数未定义/为null