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 metadata提取的PDF元数据,如何转换为一个Excel
  • ¥15 关于arduino编程toCharArray()函数的使用
  • ¥100 vc++混合CEF采用CLR方式编译报错
  • ¥15 coze 的插件输入飞书多维表格 app_token 后一直显示错误,如何解决?
  • ¥15 vite+vue3+plyr播放本地public文件夹下视频无法加载
  • ¥15 c#逐行读取txt文本,但是每一行里面数据之间空格数量不同
  • ¥50 如何openEuler 22.03上安装配置drbd
  • ¥20 ING91680C BLE5.3 芯片怎么实现串口收发数据
  • ¥15 无线连接树莓派,无法执行update,如何解决?(相关搜索:软件下载)
  • ¥15 Windows11, backspace, enter, space键失灵