[英]How to handle the JSON formatted string?
I use json.dumps() to handle the value and want to display them in the front-end. 我使用json.dumps()处理该值,并希望在前端显示它们。
I set the header to "application/json",but it doesn't work well and the quote is converted to "
我将标头设置为“ application / json”,但效果不佳,引号被转换为"
in the browser. 在浏览器中。
How do I convert them to the normal output like {"key": "value"} rather than {"key": "value"}
? 如何将它们转换为正常输出,例如{“ key”:“ value”}而不是{"key": "value"}
?
This is my url .I use web.py to handle the data. 这是我的网址 。我使用web.py处理数据。
import json
import os
import urllib2
import web
app_root = os.path.dirname(__file__)
templates_root = os.path.join(app_root, 'templates')
render = web.template.render(templates_root)
class Callback:
def GET(self):
web.header('Content-Type', 'application/json; charset=utf-8')
url = "http://www.reddit.com/r/pics/hot.json"
hdr = { 'User-Agent' : 'super happy flair bot by /u/spladug' }
req = urllib2.Request(url, headers=hdr)
html = urllib2.urlopen(req).read()
html = json.dumps(html)
func_name = web.input()['callback']
html = '{0}({1})'.format(func_name, html)
return render.callback(html)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.