在json中分别返回对象

oso9817
        "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 语句将它们分配给一个变量,然后从中制作一个干净的打印语句,但我不确定我会怎么做 .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.
唐纳德·鲍威尔

尝试添加这样的循环

for i in range(0,len(self.j['data'][champEntry]['allytips'])):
        print self.j['data'][champEntry]['allytips'][i],"\n"

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章