简体   繁体   English

使用Javascript / Angularjs下载文件,其内容以JSON格式检索

[英]File Download using Javascript / Angularjs, whose content is retrieved in JSON format

I have downloaded the file from a REST api, but its content is displayed in this format. 我已经从REST api下载了文件,但是其内容以这种格式显示。 I wish to download it instantaneously in the browser whenever it is called. 我希望在调用它时立即在浏览器中立即下载它。

{"0":" ","1":" ","2":" ","3":" ","4":"\","5":"\","6":"J","7":"F","8":"I","9":"F","10":"\","11":"\","12":"\","13":"\","14":"\","15":"\","16":"\","17":"\","18":"\","19":"\","20":" ","21":" ","22":"\","23":"C","24":"\","25":"\\b","26":"\","27":"\","28":"\","29":"\","30":"\","31":"\\b","32":"\","33":"\","34":"\","35":"\\t","36":"\\t","37":"\\b","38":"\\n","39":"\\f","40":"\","41":"\\r","42":"\\f","43":"\ ","44":"\ ","45":"\\f","46":"\","47":"\","48":"\","49":"\","50":"\","51":"\","52":"\","53":"\"} {“ 0”:“ ”,“ 1”:“ ”,“ 2”:“ ”,“ 3”:“ ”,“ 4”:“ \\ u0000”,“ 5”:“ \\ u0010” ,“ 6”:“ J”,“ 7”:“ F”,“ 8”:“ I”,“ 9”:“ F”,“ 10”:“ \\ u0000”,“ 11”:“ \\ u0001” ,“ 12”:“ \\ u0001”,“ 13”:“ \\ u0000”,“ 14”:“ \\ u0000”,“ 15”:“ \\ u0001”,“ 16”:“ \\ u0000”,“ 17”: “ \\ u0001”,“ 18”:“ \\ u0000”,“ 19”:“ \\ u0000”,“ 20”:“ ”,“ 21”:“ ”,“ 22”:“ \\ u0000”,“ 23 “:” C“,” 24“:” \\ u0000“,” 25“:” \\ b“,” 26“:” \\ u0006“,” 27“:” \\ u0006“,” 28“:” \\ u0007“ ,“ 29”:“ \\ u0006”,“ 30”:“ \\ u0005”,“ 31”:“ \\ b”,“ 32”:“ \\ u0007”,“ 33”:“ \\ u0007”,“ 34”: “ \\ u0007”,“ 35”:“ \\ t”,“ 36”:“ \\ t”,“ 37”:“ \\ b”,“ 38”:“ \\ n”,“ 39”:“ \\ f”, “ 40”:“ \\ u0014”,“ 41”:“ \\ r”,“ 42”:“ \\ f”,“ 43”:“ \\ u000b”,“ 44”:“ \\ u000b”,“ 45”:“ \\ f“,” 46“:” \\ u0019“,” 47“:” \\ u0012“,” 48“:” \\ u0013“,” 49“:” \\ u000f“,” 50“:” \\ u0014“,” 51“:” \\ u001d“,” 52“:” \\ u001a“,” 53“:” \\ u001f“}

Use the browser's webdeveloper tools (F12 in Chrome, firebug in firefox, F12 or F10 in IE) and check the request you're making for the file. 使用浏览器的网络开发人员工具(Chrome中为F12,Firefox中为firebug,IE中为F12或F10),然后检查您对文件的要求。 Check the content type and the format of the response. 检查内容类型和响应格式。 From what I'm seing, I think the "file" is recognized on the client side as a JavaScript array. 根据我的想法,我认为“文件”在客户端被识别为JavaScript数组。

Also consider setting the encoding from server-side. 还可以考虑从服务器端设置编码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM