我在 Ubuntu 16.04 上并使用 Python Dbus。我想通过 DBus 向我的客户返回一个字典列表,但似乎只能返回一个字符串数组。如果我将 dbus 签名装饰器更改为“as{v}”,则会出现异常:“ValueError: Corrupt type signature”。如何通过 DBus 返回字典列表?
@dbus.service.method("com.example.service.BtScanList", in_signature='', out_signature='as')
def getScanList(self):
btMsg("Starting BT Scan List...")
# Populate device lists ( returns dictionary --> { 'mac_address' : xxx , 'name' : xxx }
self.discoveredDevs = self.getScannedDevices()
returnList = []
for dev in self.discoveredDevs:
returnList.append(dev["name"])
return returnList
编辑:这也不起作用:
@dbus.service.method("com.example.service.BtScanList", in_signature='', out_signature='a{sv}')
def getScanList(self):
btMsg("Starting BT Scan List...")
# Populate device lists ( returns dictionary --> { 'mac_address' : xxx , 'name' : xxx }
self.discoveredDevs = self.getScannedDevices()
returnList = dbus.Array()
for dev in self.discoveredDevs:
btMsg(dev)
returnList.append(dbus.Dictionary(dev, signature='sv'))
return returnList