我已经安装了一个插件来通过我的Homebridge服务器控制我的三星电视(https://github.com/xeenon/homebridge-samsung-tv),但是开发人员没有提供config-sample.json,因此为什么我要自己制作一个。我是编码的新手,所以请告诉我我做错了什么。
到目前为止,这是该附件的配置文件的一部分(稍后我将添加ip地址和mac地址)。
if (kIsWeb) {
// running on the web!
}
当我尝试启动Homebridge时出现错误
{
"bridge": {
"name": "Homebridge",
"username": "",
"port": 4318,
"pin": "031-45-154"
},
"accessories": [{
"accessory": "samsungTv",
"name": "samsungTvAccessory",
"ip_address": "",
"macAddress": "",
"polling": "true",
"pollingInterval": "1"
}]
}
但是如果我将配置文件更改为
TypeError: Cannot read property 'forEach' of undefined
at new SamsungTvAccessory (usr/local/lib/node_modules/homebridge-samsung-tv-controller/index.js:76:10
我添加的地方
{
"bridge": {
"name": "Homebridge",
"username": "",
"port": 4318,
"pin": "031-45-154"
},
"accessories": [{
"accessory": "samsungTv",
"name": "samsungTvAccessory",
"ip_address": "",
"macAddress": "",
"polling": "true",
"pollingInterval": "1",
"enabledInputs": "true"
}]
}
我得到了错误
"enabledInputs": "true"
我将非常感谢您的帮助!
答案 0 :(得分:0)
您尝试使用有效的JSON吗?会告诉您缺少括号,这也是从源代码的第一行来看的。它应该像这样
objectVar = {
"accessory": "samsungTv",
"name": "samsungTvAccessory",
"ip_adress": "",
"macAddress": "",
"polling": "true",
"pollingInterval": "1"
}
或者在您在某处使用字符串的情况下类似:“ {\” accessory \“:\” samsungTv \“,\” name \“:\” samsungTvAccessory \“,\” ip_adress \“:\” \ “,\” macAddress \“:\” \“,\” polling \“:\” true \“,\” pollingInterval \“:\” 1 \“}”
然后有方法 JSON.stringify ( objectVar [,null, indent ])或 JSON.parse ( string )转换为字符串或返回。 Stringify 还具有可选参数-第一个是替换函数,第二个缩进(如果您希望它对用户友好的格式)。