zaten numaralı geçerli JSON verisine sahipsiniz. \"
, çıkış karakteristiğindeki bir alıntıdır (bu nedenle dize değerinin bir parçasıdır) ve [...]
bir JSON dizisi (bir Python listesine benzer) dizisidir.
Sadece JSON olarak veri yüklemek:
>>> import json
>>> jsondata = r'''{"quotes":["I could calculate your chance of survival, but you won't like it.","I'd give you advice, but you wouldn't listen. No one ever does.","I ache, therefore I am.","I've seen it. It's rubbish. (About a Magrathean sunset that Arthur finds magnificent)","Not that anyone cares what I say, but the Restaurant is on the other end of the universe.","I think you ought to know I'm feeling very depressed.","My capacity for happiness,\" he added, \"you could fit into a matchbox without taking out the matches first.","Arthur: \"Marvin, any ideas?\" Marvin: \"I have a million ideas. They all point to certain death.\"","\"What's up?\" [asked Ford.] \"I don't know,\" said Marvin, \"I've never been there.\"","Marvin: \"I am at a rough estimate thirty billion times more intelligent than you. Let me give you an example. Think of a number, any number.\" Zem: \"Er, five.\" Marvin: \"Wrong. You see?\"","Zaphod: \"Can it Trillian, I'm trying to die with dignity. Marvin: \"I'm just trying to die.\""]}'''
>>> data = json.loads(jsondata)
>>> data
{'quotes': ["I could calculate your chance of survival, but you won't like it.", "I'd give you advice, but you wouldn't listen. No one ever does.", 'I ache, therefore I am.', "I've seen it. It's rubbish. (About a Magrathean sunset that Arthur finds magnificent)", 'Not that anyone cares what I say, but the Restaurant is on the other end of the universe.', "I think you ought to know I'm feeling very depressed.", 'My capacity for happiness," he added, "you could fit into a matchbox without taking out the matches first.', 'Arthur: "Marvin, any ideas?" Marvin: "I have a million ideas. They all point to certain death."', '"What\'s up?" [asked Ford.] "I don\'t know," said Marvin, "I\'ve never been there."', 'Marvin: "I am at a rough estimate thirty billion times more intelligent than you. Let me give you an example. Think of a number, any number." Zem: "Er, five." Marvin: "Wrong. You see?"', 'Zaphod: "Can it Trillian, I\'m trying to die with dignity. Marvin: "I\'m just trying to die."']}
>>> from pprint import pprint
>>> pprint(data)
{'quotes': ["I could calculate your chance of survival, but you won't like it.",
"I'd give you advice, but you wouldn't listen. No one ever does.",
'I ache, therefore I am.',
"I've seen it. It's rubbish. (About a Magrathean sunset that "
'Arthur finds magnificent)',
'Not that anyone cares what I say, but the Restaurant is on the '
'other end of the universe.',
"I think you ought to know I'm feeling very depressed.",
'My capacity for happiness," he added, "you could fit into a '
'matchbox without taking out the matches first.',
'Arthur: "Marvin, any ideas?" Marvin: "I have a million ideas. '
'They all point to certain death."',
'"What\'s up?" [asked Ford.] "I don\'t know," said Marvin, "I\'ve '
'never been there."',
'Marvin: "I am at a rough estimate thirty billion times more '
'intelligent than you. Let me give you an example. Think of a '
'number, any number." Zem: "Er, five." Marvin: "Wrong. You see?"',
'Zaphod: "Can it Trillian, I\'m trying to die with dignity. '
'Marvin: "I\'m just trying to die."']}
>>> import random
>>> print(random.choice(data['quotes']))
I've seen it. It's rubbish. (About a Magrathean sunset that Arthur finds magnificent)
>>> print(random.choice(data['quotes']))
I ache, therefore I am.
Ben rastgele listeden tırnak birini seçmek random.choice()
function kullanılan yukarıdaki demo.
Şimdi
Dünya
Ben kızıl ötesi görebileceğiniz başım yutmak olmaz yatak
Darkness gitti: Eksik
tek şey tüm Marvin'in utterings sevdiğim, Marvin'in ninni gece Şimdi
nefret nasıl
Ben
Tatlı rüya sen ke olabilir dilek elektrik koyun saymak
deneyin uyku beni uzandı ep
nasıl Bu gibi çalışması gerekir
Aslında ... bu, teklif listesinin bir listesini veren geçerli bir jsondur. Örneğin, veri ["alıntılar"] [0] '' '' '' '' '' hayatta kalmayı hesaplayabilirdim, ama hoşuna gitmeyeceksin. ''. Bu '\ 'kaçış karakterlerini alırsınız çünkü json dizeleri dizeleri gömmüştür. – tdelaney
BTW, dünyanın en büyük edebiyatlarından bazı alıntılar yaptığını görmek harika. – tdelaney