"allytips": [
"Jax can Leap Strike to friendly units, including wards. You can use them to plan your escape.",
"Jax benefits greatly from items that have both Ability Power and Attack Damage such as Guinsoo's Rageblade and Hextech Gunblade."
],
我试图将allytips中的上述数据作为单独的对象返回,这样我就可以以更吸引人的方式格式化/样式化,例如在每个字符串末尾的\ n我尝试使用for语句因为我认为它会使它更易于访问,但它没有,它只打印一个通常是最后一个的对象。我可以做if语句将它们分配给变量然后从中创建一个干净的print语句但是我不确定我将如何做.format()因为如果它不存在它会给我一个错误,如果我做{n {4} \ n {5}并且它们不存在,我会有很多空行
try:
for tips in self.j['data'][champEntry]['allytips']:
self.allyTips0 = tips
print(tips)
allyRaw = self.j['data'][champEntry]['allytips']
print(allyRaw)
这就是它返回的第一行我怎么说它只是一次只打印一个对象而不是最后一行
Remember that nearby enemies can see which wall you're in.
["Look at the line-up of both your team and the enemy's team when picking your form.", "Remember that nearby enemies can
see which wall you're in."]
我试图让它看起来像这样
Look at the line-up of both your team and the enemy's team when picking your form.
Remember that nearby enemies can see which wall you're in.
答案 0 :(得分:0)
尝试使用split()方法,该方法将通过分隔符创建数组进行拆分。然后按索引选择。
allyRaw1 = self.j['data'][champEntry]['allytips'].split(',')[0]
allyRaw2 = self.j['data'][champEntry]['allytips'].split(',')[1]
答案 1 :(得分:0)
尝试添加像这样的循环
for i in range(0,len(self.j['data'][champEntry]['allytips'])):
print self.j['data'][champEntry]['allytips'][i],"\n"