{"data":[{"node":"emqx@127.0.0.1","topic":"4e4a3668bf514c6f89738c5f3eec6285"},{"node":"emqx@127.0.0.1","topic":"05f170438ab44d769f9f67c1406316c2"},{"node":"emqx@127.0.0.1","topic":"fcef086b0ea443429cc867a35fb630fd"},{"node":"emqx@127.0.0.1","topic":"topic_aaa"}],"meta":{"count":4,"hasnext":false,"limit":20,"page":1}}是字符串呢
时间: 2023-07-05 22:36:32 浏览: 113
如果你要获取的是字符串,那么可以使用以下代码来获取第一个topic的字符串值:
```python
import json
json_str = '{"data":[{"node":"emqx@127.0.0.1","topic":"4e4a3668bf514c6f89738c5f3eec6285"},{"node":"emqx@127.0.0.1","topic":"05f170438ab44d769f9f67c1406316c2"},{"node":"emqx@127.0.0.1","topic":"fcef086b0ea443429cc867a35fb630fd"},{"node":"emqx@127.0.0.1","topic":"topic_aaa"}],"meta":{"count":4,"hasnext":false,"limit":20,"page":1}}'
data = json.loads(json_str)
topic_str = data['data'][0]['topic']
print(topic_str)
```
输出结果为:
```
'4e4a3668bf514c6f89738c5f3eec6285'
```
如果你要获取所有topic的字符串值,那么可以使用以下代码:
```python
import json
json_str = '{"data":[{"node":"emqx@127.0.0.1","topic":"4e4a3668bf514c6f89738c5f3eec6285"},{"node":"emqx@127.0.0.1","topic":"05f170438ab44d769f9f67c1406316c2"},{"node":"emqx@127.0.0.1","topic":"fcef086b0ea443429cc867a35fb630fd"},{"node":"emqx@127.0.0.1","topic":"topic_aaa"}],"meta":{"count":4,"hasnext":false,"limit":20,"page":1}}'
data = json.loads(json_str)
topics_str = [d['topic'] for d in data['data']]
print(topics_str)
```
输出结果为:
```
['4e4a3668bf514c6f89738c5f3eec6285', '05f170438ab44d769f9f67c1406316c2', 'fcef086b0ea443429cc867a35fb630fd', 'topic_aaa']
```
阅读全文