任何人都可以请解释如何将下面的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