我需要根据配置值创建正确的Json。例如,如果config具有下一个键值:channel_id = 1,2,3,4
我需要得到json:channel_id" : [1,2,3,4]
,但现在我得到"channel_id" : "1,2,3,4"
myfilter = dict(
client_id=config['client_id'],
channel_id=config['channel_id']
)
x = json.dumps(myfilter)
答案 0 :(得分:1)
您需要首先将配置值解析/拆分为public void run() {
if (!isLoading && !playerList.isEmpty()) {
this.isLoading = true;
ArrayList<Player> clonedList = (ArrayList<Player>)playerList.clone();
playerList.clear();
try {
for (Player player : clonedList) {
main.getDataManager().loadPlayer(player);
}
} catch (Exception e) { }
this.isLoading = false;
}
}
:
list
鉴于这将产生字符串,您可能希望首先将它们转换为整数(即myfilter = dict(
client_id=config['client_id'],
channel_id=[x.strip() for x in config['channel_id'].split(",")] # split and strip
)
而不是int(x)
)。