任何人都可以請解釋如何將下面的json數據轉換爲python中的字符串。這是非常大的,但我需要你的幫助...... 您可以通過以下鏈接看到: - http://api.openweathermap.org/data/2.5/forecast/daily?q=delhi&mode=json&units=metric&cnt=7&appid=146f5f89c18a703450d3bd6737d4fc94 請表明,它的解決方案是爲我的項目的重要:-)將數據從Json轉換爲python中的字符串
回答
您可以在python像解碼JSON字符串這樣的:
import json
data = json.loads('json_string')
import requests
url = 'http://api.openweathermap.org/data/2.5/forecast/daily?q=delhi&mode=json&units=metric&cnt=7&appid=146f5f89c18a703450d3bd6737d4fc94'
response = requests.get(url)
response.text # this is a string
response.json() # this is a json dictionary
s = "The City is {city[name]} todays HIGH is {list[0][temp][max]}".format(**response.json())
print s
謝謝先生.... –
一些簡單的代碼,會從你的頁面讀取JSON併產生一個Python解釋如下。我已經使用了相鄰字符串的隱式連接來改進代碼的佈局。
import json
import urllib.request
f = urllib.request.urlopen
(url="http://api.openweathermap.org/data/2.5/forecast/daily?"
"q=delhi&mode=json&units=metric&"
"cnt=7&appid=146f5f89c18a703450d3bd6737d4fc94")
content = f.read()
result = json.loads(content.decode("utf-8"))
print(result)
這給了我下面的輸出(我還沒有在代碼風格顯示,因爲它會出現在一個長行):
{「城市」:{「座標」:{「LAT ':28.666668,'lon':77.216667},'country':'IN','id':1273294,'population':0,'name':'Delhi'},'cnt':7,'message': 0.0081,'list':[{'dt':1467093600,'weather':[{'icon':'01n','id':800,'description':'clear sky','main':'Clear' '溼度':82,'雲':0,'壓力':987.37,'速度':2.63,'temp':{'max':32,'eve':32,'night':30.67, 'min':30.67,'day':32''morn':32},'deg':104},{'dt':1467180000,'weather':[{'icon':'10d','id' :501,'description':'中雨','main':'Rain'}],'humidit y':74,'雲':12,'壓力':989.2,'速度':4.17,'雨':9.91,'temp':{'max':36.62,'eve':36.03,'night': 31.08,'min':29.39,'day':35.61,'morn':29.39},'deg':126},{'dt':1467266400,'weather':[{'icon':'02d' '801','description':'少雲','主':'雲'}],'溼度':71,'雲':12,'壓力':986.56,'速度':3.91,'temp ':{'max':36.27,'eve':35.19,'night':30.87,'min':29.04,'day':35.46,'morn':29.04},'deg':109',{'dt ':1467352800,'weather':[{'icon':'10d','id':502,'description':'heavy intensity rain','main':'Rain'}],'humidity':100, '雲':48,'壓力':984.48,'速度':0,'雨':18.47,'temp':{'max':30.87,'eve':30.87,'night':28.24,'min' :24.96,'day':27.16,'morn':24.96},'deg':0},{'dt':1467439200,'weather':[{'icon':'10d','id' '描述':'中雨','主':'雨'}],'溼度':0,'雲':17,'壓力':983.1,'速度':6.54,'雨':5.31' temp':{'max':35.48,'eve':32.96,'night':27.82, 'min':27.82,'day':35.48,'morn':29.83},'deg':121},{'dt':1467525600,'weather':[{'icon':'10d',' :501,'description':'中雨','main':'Rain'}],'humidity':0,'clouds':19,'pressure':984.27,'speed':3.17,'rain': 7.54,'temp':{'max':34.11,'eve':34.11,'night':27.88,'min':27.53,'day':33.77,'morn':27.53},'deg':133} ,'''','','''','''','''','''''''','''''''''''','''''''','''''', ':0,'雲':60,'壓力':984.82,'速度':5.28,'雨':54.7,'temp':{'max':33.12,'eve':33.12,'night':26.15 ,'min':25.78,'day':31.91,'morn':25.78},'deg':88}],'cod':'200'}
謝謝先生:-) –
很高興。既然它看起來可以幫助你,你可能想要考慮將它標記爲已接受,或者對其進行提升 – holdenweb
- 1. 將JSON數據轉換爲字符串
- 2. 如何將JSON字符串轉換爲Python數據結構
- 3. 轉:將字符串數組轉換爲Json數組字符串
- 4. 將字符串轉換爲json數組
- 5. 將Json數組轉換爲字符串
- 6. 字符串轉換爲JSON數據
- 7. 將JSON字符串轉換爲python中的字典
- 8. 將非JSON字符串轉換爲JSON
- 9. 正確地將字符串轉換爲PHP中的JSON數據
- 10. 將字符串轉換爲複數python
- 11. 將Python數組轉換爲字符串
- 12. 將字符串轉換爲python數量
- 13. Python將字符串轉換爲整數?
- 14. 將字符串數組轉換爲JSON格式的字符串
- 15. 將字符串轉換爲Python中的打包數據
- 16. 將json字符串轉換爲iphone中的xml字符串
- 17. 將json轉換爲數組php將數組轉換爲字符串轉換
- 18. 如何將字符串數據轉換爲python中的JSON對象?
- 19. 將字節字符串轉換爲python中的字符串
- 20. 如何將JSON字符串轉換爲字符串數組?
- 21. 將JSON字符串轉換爲C#字符串數組
- 22. 將json字符串數據轉換回python圖像對象
- 23. 如何將json字符串轉換爲python中的avro?
- 24. 將字符串轉換爲數據集
- 25. 將數據集轉換爲與JSON字符串的關係
- 26. Python將字符串轉換爲字典
- 27. 將python字典轉換爲字符串
- 28. 將字符串轉換爲字典python
- 29. 將字符串轉換爲python字典
- 30. 將一個字符串中的數字轉換爲係數python
json已經是一個字符串... –
' json'模塊包含'dumps'和'loads'的方法,它們從本地對象(字典,列表等等)來回執行序列化,然後傳輸到其他局域網軌距。 –
最好展示你已經嘗試過的東西,並解釋你的目標是什麼。可能會有更好的解決方案,而不是像你想的那樣去做,而環境可以幫助人們思考它。 – Jeff