使用Python统计JSON响应中值的出现次数可以通过以下步骤实现:
import json
from collections import Counter
response = '{"key1": "value1", "key2": "value2", "key3": "value1"}'
data = json.loads(response)
values = list(data.values())
value_counts = Counter(values)
for value, count in value_counts.items():
print(f"{value}: {count}次")
完整的代码示例:
import json
from collections import Counter
response = '{"key1": "value1", "key2": "value2", "key3": "value1"}'
data = json.loads(response)
values = list(data.values())
value_counts = Counter(values)
for value, count in value_counts.items():
print(f"{value}: {count}次")
这段代码将统计JSON响应中每个值的出现次数,并打印出来。你可以根据实际情况修改response
变量的值来适应不同的JSON响应。
领取专属 10元无门槛券
手把手带您无忧上云