English 中文(简体)
Django HttpResponses条 JSON 双倍越狱打破jQuery
原标题:Django HttpResponse strips JSON of double escapes breaks jQuery

我对Json和Django有个有趣的问题。我想我把它的范围缩小到这个问题上。问题是我有一个Json的目标,像这样的东西:

{"embed": "<iframe width= 640  height= 360  src= http://www.youtube.com/embed/Sw5Gk1L4LQE?wmode=opaque  frameborder= 0  allowfullscreen></iframe>"}

在 PDB 中, 如果我用简单json. dumps 打印出来,

{"embed": "<iframe width=\"640\" height=\"360\" src=\"http://www.youtube.com/embed/Sw5Gk1L4LQE?wmode=opaque\" frameborder=\"0\" allowfullscreen></iframe>"}

实际的 HttpResponse 对象已经从每组双倍逃逸中 移除了一条斜线 。

return HttpResponse(simplejson.dumps(result),  application/json 

{"embed": "<iframe width="640" height="360" src="http://www.youtube.com/embed/Sw5Gk1L4LQE?wmode=opaque" frameborder="0" allowfullscreen></iframe>"}

在客户身上,我使用jQuery s assetJSON,而我和有独一个逃犯人物(第3个)的人有问题,因为没有人看到他们逃跑。 但实际上JSON是有效的,因为当我在控制台直接用JSON直接分析它时,JSON作为第2个,但实际上JSON并不有效(根据JSONLint.com的说法 ) 。

我有什么办法能把JSON的物体 从决哥拿到客户手里 并保持密码完整吗?

最佳回答

于是一小时后,我终于意识到我在这个小错误上犯了几个小错误,使所有事情都大打折扣。 我在当地装上了这个网页,而不是通过Django(我是为了测试我正在做的jQuery Mobile ) 。

在当地的档案里,我复制/粘贴了JSON在Django的视图中的输出。

我试图用JSONP的电话 进入那个景象, 并且因为 JQuery JSONCallack 它的投射错误。

最后,测试的正确方式是通过Django为HTML服务,这样我就不必使用JSONP, 当我这样做时,那个ProcessJSON接受了单引出双重报价的JSON ",因为据说它不会接受复制和粘贴,因为这不是一个回应对象。

希望我的错误将来能帮助别人

问题回答

暂无回答




相关问题
How to get two random records with Django

How do I get two distinct random records using Django? I ve seen questions about how to get one but I need to get two random records and they must differ.

Moving (very old) Zope/Plone Site to Django

I am ask to move data from a (now offline) site driven by Plone to a new Django site. These are the version informations I have: Zope Version (unreleased version, python 2.1.3 ) Python Version 2.1....

Can Django models use MySQL functions?

Is there a way to force Django models to pass a field to a MySQL function every time the model data is read or loaded? To clarify what I mean in SQL, I want the Django model to produce something like ...

Flexible pagination in Django

I d like to implement pagination such that I can allow the user to choose the number of records per page such as 10, 25, 50 etc. How should I go about this? Is there an app I can add onto my project ...

is it convenient to urlencode all next parameters? - django

While writing code, it is pretty common to request a page with an appended "next" query string argument. For instance, in the following template code next points back to the page the user is on: &...

Pragmatically adding give-aways/freebies to an online store

Our business currently has an online store and recently we ve been offering free specials to our customers. Right now, we simply display the special and give the buyer a notice stating we will add the ...

热门标签