admin管理员组文章数量:1335847
I'm new to python and it seems that all my JSON data is bined with u' prefix as such:
{u'number': u'12345666', u"items"...}
I don't need this data (unicode or whatever) as I want to print the string into a Javascript variable:
var obj = data; // data is the object above.
My python looks something like this;
index.html:
var obj = ${data};
I'm using the moko framework for templating.
// getitems() return {'number':'12312...}
context = {'data': getitems(self)}
self.render_response('index.html',**context)
The processed javascript output data look like this:
var obj = {u'number': u'12345666', u"items"...}
This is my problem.
I'm new to python and it seems that all my JSON data is bined with u' prefix as such:
{u'number': u'12345666', u"items"...}
I don't need this data (unicode or whatever) as I want to print the string into a Javascript variable:
var obj = data; // data is the object above.
My python looks something like this;
index.html:
var obj = ${data};
I'm using the moko framework for templating.
// getitems() return {'number':'12312...}
context = {'data': getitems(self)}
self.render_response('index.html',**context)
The processed javascript output data look like this:
var obj = {u'number': u'12345666', u"items"...}
This is my problem.
Share Improve this question edited Mar 28, 2013 at 17:13 Robᵩ 169k20 gold badges249 silver badges323 bronze badges asked Mar 28, 2013 at 16:37 KivyliusKivylius 6,56712 gold badges47 silver badges74 bronze badges 9- 6 You are confusing JSON with printing a dictionary. – freakish Commented Mar 28, 2013 at 16:39
-
3
You do not want to remove the
u''
, it is only an indication that you are looking at unicode strings. Your templating code will take care of JSON, provided you encode to JSON first. – Martijn Pieters Commented Mar 28, 2013 at 16:39 - 2 +1: Simply because I don't know why this question has so many downvotes? – freakish Commented Mar 28, 2013 at 16:45
- @freakish I don't understand it to. They expect everyone to be an expect and people new are simple down voted. – Kivylius Commented Mar 28, 2013 at 17:02
- 1 @CezarisLT - I don't care about professionalism, I care about munication. In this instance, I had no idea what you were talking about. (Ditto for "tempting" and "procced". I had to guess at your meanings there.) – Robᵩ Commented Mar 28, 2013 at 17:12
1 Answer
Reset to default 8The problem is that you are converting a dictionary to a string (probably Mako does str(...)
for you). But you should jsonify it, i.e.
import json
context = { 'data': json.dumps(getitems(self)) }
本文标签: javascriptRemove u39 infront of my JSON dataStack Overflow
版权声明:本文标题:javascript - Remove u' infront of my JSON data - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742399149a2467530.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论