json.dumps() を使用して値を処理し、それらをフロントエンドに表示したいと考えています。
ヘッダーを「application/json」に設定したのですが、うまく動かず、引用符が"
ブラウザで変換されてしまいます。
ではなく {"key": "value"} のような通常の出力に変換するにはどうすればよい
{"key": "value"}
ですか?
これは私のURLです。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)