javascript - Remove u' infront of my JSON data - Stack Overflow

I'm new to python and it seems that all my JSON data is bined with u' prefix as such:{u'

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
 |  Show 4 more ments

1 Answer 1

Reset to default 8

The 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)) }

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742399149a4436554.html

相关推荐

  • javascript - Remove u' infront of my JSON data - Stack Overflow

    I'm new to python and it seems that all my JSON data is bined with u' prefix as such:{u'

    2天前
    40

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信