Tornado JSON 输出新行每个数据而不是每个字符
Tornado JSON output new line each data instead of each character
我无法相应地输出 json 数据。相反,它输出每个字符换行。代码:
import tornado.web
import tornado.ioloop
import tornado.httpserver
from tornado.escape import json_encode
class Handler(tornado.web.RequestHandler):
def get(self):
#Sample Json Data
jsondata = '{ "name": "DU-001", "lat": "4.901787", "lng": "114.925919"}' \
',{ "name": "DU-002", "lat": "4.901789", "lng": "114.925929"}'
#Rendering to web file
self.render("web/index.html", title="Lock-On", mydata=json_encode(jsondata))
来自 HTML 代码:循环遍历 mydata 以输出列表
{% for item in mydata %}
{{ item }} <br />
{% end %}
输出结果示例:
"
{
\
"
n
a
m
e
\
"
:
\
"
D
U
-
0
0
1
\
"
使您的数据成为字典列表而不是字符串。
jsondata = [{"name": "DU-001", "lat": "4.901787", "lng": "114.925919"},{ "name": "DU-002", "lat": "4.901789", "lng": "114.925929"}]
我无法相应地输出 json 数据。相反,它输出每个字符换行。代码:
import tornado.web
import tornado.ioloop
import tornado.httpserver
from tornado.escape import json_encode
class Handler(tornado.web.RequestHandler):
def get(self):
#Sample Json Data
jsondata = '{ "name": "DU-001", "lat": "4.901787", "lng": "114.925919"}' \
',{ "name": "DU-002", "lat": "4.901789", "lng": "114.925929"}'
#Rendering to web file
self.render("web/index.html", title="Lock-On", mydata=json_encode(jsondata))
来自 HTML 代码:循环遍历 mydata 以输出列表
{% for item in mydata %}
{{ item }} <br />
{% end %}
输出结果示例:
"
{
\
"
n
a
m
e
\
"
:
\
"
D
U
-
0
0
1
\
"
使您的数据成为字典列表而不是字符串。
jsondata = [{"name": "DU-001", "lat": "4.901787", "lng": "114.925919"},{ "name": "DU-002", "lat": "4.901789", "lng": "114.925929"}]