weixin_33713503 2016-04-11 16:06 采纳率: 0%
浏览 29

特殊字符问题

I am facing an issue where special characters are not being printed properly on my webpage.

So, I am making an ajax query, with python script at backend :

$.ajax({                                                                       
    url: BACK_END_LOC + 'get_search_results',                                  
    data: ({keyword1: keyword1,                                                
            keyword2: keyword2,                                                
            start_time: encodeURI(start_time),                                 
            end_time: encodeURI(end_time),                                     
            dataset: $("#dataset").val()                                       
            }),                                                                

    success: function(data) {                                                  
        response = eval('(' + data + ')');                                     
        if (response.error_code == 0) {                                        
            render_event_search_results(response.data);                        
        } else {                                                               
        alert('Error_code:' + response.error_code + ', Error_msg:' + response.error_msg);
        }                                                                      
    },  

Python is returning a json object:

def get_search_results(req, keyword1, keyword2, start_time, end_time, dataset):
s = keyword1 + "," + keyword2

# get filtered events
results = get_filtered_events(dataset, keyword1, keyword2, start_time, end_time)

try:
    r = {'error_code': 0, 'error_msg': 'OK', 'data': results}

except Exception, e:
    raise e
    r = {'error_code': 1, 'error_msg': 'Oops'}

return simplejson.dumps(r)

Now, one field of this object has special characters. When I try to print this field on html "alert(gEvents[0].signature)", it is being printed as : \u0432\u0438\u0434\u0435\u043e_storm

How can I get it printed like :видео_storm, which is the actual text.

  • 写回答

1条回答 默认 最新

  • weixin_33716557 2016-04-11 16:25
    关注

    replace

    return simplejson.dumps(r)
    

    with

    return simplejson.dumps(r,ensure_ascii=False)
    
    评论

报告相同问题?

悬赏问题

  • ¥15 从键盘输入不管多少字符或者数组 输出的时候先提示输出再显示结果 输出的时候字符间间隔一个空格符
  • ¥30 频率分析法分析绘制奈奎斯特图、波特图
  • ¥15 弹出来一万个系统找不到指定的文件框框,怎么解决
  • ¥15 ADS生成的微带线为什么是蓝色空心的
  • ¥15 求一下解题思路,完全不懂
  • ¥15 tensorflow
  • ¥15 densenet网络结构中,特征以cat方式复用后是怎么进行误差回传的
  • ¥15 STM32G471芯片spi设置了8位,总是发送16位
  • ¥15 R语言并行计算beta-NTI中tree文件的类型
  • ¥15 如何解读marsbar导出的ROI数据?